Advertisement
Guest User

Untitled

a guest
Sep 6th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Julia 0.54 KB | None | 0 0
  1. # How does map determine the correct type for the output of the following two map calls? Does it assume the array all has the same type as `f(a[1])` and put things into a `Vector{Any}` after seeing that the types are not the same?
  2.  
  3. julia> a = [1, 2, 3]
  4. 3-element Array{Int64,1}:
  5.  1
  6.  2
  7.  3
  8.  
  9. julia> f(x) = (x == 1) ? "a" : 0
  10. f (generic function with 1 method)
  11.  
  12. julia> map(f, a)
  13. 3-element Array{Any,1}:
  14.   "a"
  15.  0
  16.  0
  17.  
  18. julia> f(x) = (x == 1) ? 1 : 0
  19. f (generic function with 1 method)
  20.  
  21. julia> map(f, a)
  22. 3-element Array{Int64,1}:
  23.  1
  24.  0
  25.  0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement