How to handle Array of Arrays?

How to construct ff and gg from hh in the code below? Thx!

f(x) = [1;1]
g(x) = x*[1;1]
h(x) = [1;1], x*[1;1]
ff = mapreduce(f,vcat, [1 2 3])
gg = mapreduce(g,vcat, [1 2 3])
hh = map(h, [1 2 3])

this maybe:

julia> fff, ggg = vcat.(hh...)
([1, 1, 1, 1, 1, 1], [1, 1, 2, 2, 3, 3])

2 Likes

Aha! Thx! What does … following hh refer to?

It’s called splatting. You can check out help in the Julia REPL for this via ?...

help?> ...
search: ...

  ...


  The "splat" operator, ..., represents a sequence of arguments. ... can
  be used in function definitions, to indicate that the function accepts
  an arbitrary number of arguments. ... can also be used to apply a
  function to a sequence of arguments.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> add(xs...) = reduce(+, xs)
  add (generic function with 1 method)
  
  julia> add(1, 2, 3, 4, 5)
  15
  
  julia> add([1, 2, 3]...)
  6
  
  julia> add(7, 1:100..., 1000:1100...)
  111107
1 Like

Right. Thx!