# How do I compose two vectorized functions?

**URL:** <https://discourse.julialang.org/t/how-do-i-compose-two-vectorized-functions/29026>\
**Category:** New to Julia\
**Created:** [September 21, 2019, 11:10am UTC](https://discourse.julialang.org/t/how-do-i-compose-two-vectorized-functions/29026 "2019-09-21T11:10:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [September 21, 2019, 11:10am UTC](https://discourse.julialang.org/t/how-do-i-compose-two-vectorized-functions/29026/1 "2019-09-21T11:10:50Z")

</div>

How do I compose two vectorized functions?

```julia
julia> A = [1.0, 2.0, 3.0]
3-element Array{Float64,1}:
 1.0
 2.0
 3.0

julia> sin.(cos.(A))
3-element Array{Float64,1}:
  0.5143952585235492
 -0.4042391538522658
 -0.8360218615377305

julia> (sin. ∘ cos.)(A)
ERROR: syntax: missing comma or ) in argument list
Stacktrace:
 [1] top-level scope at REPL[8]:0

```

---

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [September 21, 2019, 11:16am UTC](https://discourse.julialang.org/t/how-do-i-compose-two-vectorized-functions/29026/2 "2019-09-21T11:16:41Z")

</div>

```julia
julia> (sin ∘ cos).(A)
3-element Array{Float64,1}:
  0.5143952585235492
 -0.4042391538522658
 -0.8360218615377305

```

---

<div class="post-metadata">

**Author:** ![StevenSiew](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevensiew/32/218393_2.png) [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Post date:** [September 21, 2019, 11:21am UTC](https://discourse.julialang.org/t/how-do-i-compose-two-vectorized-functions/29026/3 "2019-09-21T11:21:02Z")

</div>

Thank you.

So i should compose the two functions first then vectorized the resultant function on the data

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 21, 2019, 12:32pm UTC](https://discourse.julialang.org/t/how-do-i-compose-two-vectorized-functions/29026/4 "2019-09-21T12:32:08Z")

</div>

> [@StevenSiew](#):
>
> So i should compose the two functions first then vectorized the resultant function on the data

`sin.(cos.(A))` already “fuses” the functions into a single pass over the data, essentially equivalent to `(sin ∘ cos).(A)`: [More Dots: Syntactic Loop Fusion in Julia](https://julialang.org/blog/2017/01/moredots)
