# Initiate an array of functions

**URL:** <https://discourse.julialang.org/t/initiate-an-array-of-functions/81834>\
**Category:** General Usage\
**Created:** [May 28, 2022, 1:34pm UTC](https://discourse.julialang.org/t/initiate-an-array-of-functions/81834 "2022-05-28T13:34:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [May 28, 2022, 1:34pm UTC](https://discourse.julialang.org/t/initiate-an-array-of-functions/81834/1 "2022-05-28T13:34:39Z")

</div>

I have func1 and func2.

When I create an array of the functions, like:

julia\> A = [func1, func2]  
2-element Vector{Function}:  
func1 (generic function with 4 methods)  
func2 (generic function with 4 methods)

That is good. But

julia\> B = [func1]  
1-element Vector{typeof(func1)}:  
func1 (generic function with 4 methods)

How can I make B to be 1-element Vector{Function}?

---

<div class="post-metadata">

**Author:** ![magister-ludi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/magister-ludi/32/4003_2.png) [@magister-ludi](https://discourse.julialang.org/u/magister-ludi)\
**Post date:** [May 28, 2022, 1:40pm UTC](https://discourse.julialang.org/t/initiate-an-array-of-functions/81834/2 "2022-05-28T13:40:02Z")

</div>

This should do it:

```julia
B = Function[func1]

```

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [May 28, 2022, 1:49pm UTC](https://discourse.julialang.org/t/initiate-an-array-of-functions/81834/3 "2022-05-28T13:49:29Z")

</div>

but why? this doesn’t seem very useful because `Function` is an abstract type. what are you trying to do

---

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [May 28, 2022, 2:10pm UTC](https://discourse.julialang.org/t/initiate-an-array-of-functions/81834/4 "2022-05-28T14:10:51Z")

</div>

> [@magister-ludi](#):
>
> `B = Function[func1]`

Thanks. That works, likewise:

B = Vector{Function}([func1])

But wonder why B = [func1] doesn’t get me a 1-element Vector{Function}?

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [May 28, 2022, 3:15pm UTC](https://discourse.julialang.org/t/initiate-an-array-of-functions/81834/5 "2022-05-28T15:15:53Z")

</div>

Because Julia often tries to to give you the tightest type inference possible, as this often helps with performance. It is strange for functions because each function has its own type, so `[func1]` will become a `Vector{typeof(func1)}` which is _technically_ more performant but at same time almost useless (because the vector can now only store references to the same single function instead of multiple distinct functions, defeating the purpose of a `Vector`). The same happens if you do `[nothing]` (the type will be `Vector{Nothing}`) but here it is more understandable because there is no intermediary type between `Nothing` and `Any` so the only reasonable types we could expect are either the almost useless `Vector{Nothing}` or the very inefficient `Vector{Any}`.
