Let foo
take a variable number of string arguments and pass them to bar
. foo
and bar
have the same signatures.
julia> function foo(strings::String...)
bar(strings)
println("Hello, foo")
end
foo (generic function with 1 method)
julia> function bar(strings::String...)
println("Hello, bar")
end
bar (generic function with 1 method)
I expected this to work and it does without the varargs
elipsis. But as written above, I get as follows–
julia> foo("abc")
ERROR: MethodError: no method matching bar(::Tuple{String})
Closest candidates are:
bar(::String...) at REPL[2]:2
Stacktrace:
[1] foo(::String, ::Vararg{String,N} where N) at ./REPL[1]:2
julia> foo("abc", "def")
ERROR: MethodError: no method matching bar(::Tuple{String,String})
Closest candidates are:
bar(::String...) at REPL[2]:2
Stacktrace:
[1] foo(::String, ::Vararg{String,N} where N) at ./REPL[1]:2
I need an iterable collection of foo
’s arguments in bar
. Can someone explain why this is not working and what the proper way to accomplish this is? TIA.