# Weird behavior with "map" function

**URL:** https://discourse.julialang.org/t/weird-behavior-with-map-function/81816
**Category:** New to Julia
**Created:** [May 27, 2022, 8:39pm UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816 "2022-05-27T20:39:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![lancejnelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lancejnelson/32/21898_2.png) [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)
#### Post date: [May 27, 2022, 8:39pm UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816/1 "2022-05-27T20:39:26Z")

</div>

Simple example:

```nohighlight
a = [5.4,2.7,8]
b = [5.3,2.1,"Jump"]

typeof(a) # Vector{Float64}
typeof(b) # Vector{Any}

```

just as expected. Now try using map function:

```nohighlight
map(typeof,[a,b])  

```

produces this:

```nohighlight

2-element Vector{DataType}:
 Vector{Any} (alias for Array{Any, 1})
 Vector{Any} (alias for Array{Any, 1})

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [May 27, 2022, 8:43pm UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816/2 "2022-05-27T20:43:27Z")

</div>

What you’re missing is `[a,b]` promotes.

---

<div class="post-metadata">

### Author: ![lancejnelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lancejnelson/32/21898_2.png) [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)
#### Post date: [May 27, 2022, 8:58pm UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816/3 "2022-05-27T20:58:21Z")

</div>

👍 👊 Thanks

---

<div class="post-metadata">

### Author: ![lancejnelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lancejnelson/32/21898_2.png) [@lancejnelson](https://discourse.julialang.org/u/lancejnelson)
#### Post date: [May 27, 2022, 9:01pm UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816/4 "2022-05-27T21:01:34Z")

</div>

Although this seemed to work as expected:

```nohighlight
a = 5.6 #Float
b = 1 #Integer
c = false # bool
d = "Jump" # string
e = 1//2 # Rational
[a,b,c,d,e] .|> typeof

```

I suppose there is no promotion rule for string and bool

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [May 27, 2022, 9:30pm UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816/5 "2022-05-27T21:30:10Z")

</div>

What would the promotion of String and Bool be?

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [May 28, 2022, 2:03am UTC](https://discourse.julialang.org/t/weird-behavior-with-map-function/81816/6 "2022-05-28T02:03:53Z")

</div>

It _is_ kind of weird to me that `Vector{Float64}` is promoted to `Vector{Any}`. It doesn’t seem like there’d be a performance benefit to allocating a new array with an abstract element type (of course, promotion is easy to get around: `Any[a, b]`). Besides, it doesn’t look like promoting parameters happen in general:

```julia
mutable struct X{T}
    y::T 
end

a = X(1.5)
b = X{Any}(1)
f = [a,b]
#=
2-element Vector{X}:
 X{Float64}(1.5)
 X{Any}(1)
=#

```
