Does (args...) work with any iterable args?


#1

The title is self explanatory!


#2

Should do - for example, splat on positional arguments even works for a Generator:

julia> f(x...) = sum(x)
f (generic function with 1 method)

julia> x = (i ^ 2 for i in 1:10)
Base.Generator{UnitRange{Int64},##1#2}(#1,1:10)

julia> f(x...)
385

Or splat on keyword arguments (must use Symbol):

julia> g(; y...) = Dict(y)

julia> y = (Symbol(k) => v ^ 2 for (k, v) in zip(["a", "b", "c"], 1:3))
Base.Generator{Base.Zip2{Array{String,1},UnitRange{Int64}},##9#10}(#9,Base.Zip2{Array{String,1},UnitRange{Int64}}(String["a","b","c"],1:3))

julia> g(; y...)
Dict{Symbol,Int64} with 3 entries:
  :c => 9
  :a => 1
  :b => 4

#3

Why don’t you just ask Julia instead? I.e. try it out and see what happens, and then ask if something is unclear.


#4

Julia’s answer!

julia> type T
           a::Vector
       end

julia> import Base: start, next, done

julia> start(a::T) = a.a[1]
start (generic function with 60 methods)

julia> next(a::T, i) = a.a[i], i+1
next (generic function with 72 methods)

julia> done(a::T, i) = i > length(a.a)
done (generic function with 57 methods)

julia> for i in T([1,2,3])
           print(i)
       end
123

julia> print(T([1,2,3])...)
123

#5

An even cooler iterable with Channel (Julia 0.6):

0.6.0-rc3.0> f(x) = Channel(ctype=Int, csize=5) do c
                 for i in 0:x
                     push!(c, i % 10)
                 end
             end
f (generic function with 1 method)

0.6.0-rc3.0> x = f(19)
Channel{Int64}(sz_max:5,sz_curr:5)

0.6.0-rc3.0> println(x...)
01234567890123456789

0.6.0-rc3.0> println(x...)
# nothing - Channel has been exhausted