# Varargs function chaining

**URL:** <https://discourse.julialang.org/t/varargs-function-chaining/5534>\
**Category:** General Usage\
**Created:** [August 24, 2017, 7:36am UTC](https://discourse.julialang.org/t/varargs-function-chaining/5534 "2017-08-24T07:36:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [August 24, 2017, 7:36am UTC](https://discourse.julialang.org/t/varargs-function-chaining/5534/1 "2017-08-24T07:36:54Z")

</div>

Let `foo` take a variable number of string arguments and pass them to `bar`. `foo` and `bar` have the same signatures.

```julia
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
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.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [August 24, 2017, 7:57am UTC](https://discourse.julialang.org/t/varargs-function-chaining/5534/2 "2017-08-24T07:57:47Z")

</div>

You need

```julia
bar(strings...)

```

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [August 24, 2017, 8:47am UTC](https://discourse.julialang.org/t/varargs-function-chaining/5534/3 "2017-08-24T08:47:04Z")

</div>

Thanks. That did it with one twist.

```julia
julia> function foo(strings::String...)
           println("foo: ", typeof(strings))
           bar(strings)
       end
foo (generic function with 1 method)

julia> function bar(strings...)
           println("bar: ", typeof(strings))
           println("bar: ", typeof(strings[1]))
       end
bar (generic function with 1 method)julia> foo("abc")

foo: Tuple{String}
bar: Tuple{Tuple{String}}
bar: Tuple{String}

julia> foo("abc", "def")
foo: Tuple{String,String}
bar: Tuple{Tuple{String,String}}
bar: Tuple{String,String}

```

So `strings` within `bar` is not the same type as `strings` within foo. But `strings[1]` within `bar` is. Thanks again.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [August 24, 2017, 8:54am UTC](https://discourse.julialang.org/t/varargs-function-chaining/5534/4 "2017-08-24T08:54:27Z")

</div>

The point was to define

```julia
julia> function foo(strings::String...)
           println("foo: ", typeof(strings))
           bar(strings...)
       end

```

which will circumvent that additional level of `Tuple`.

---

<div class="post-metadata">

**Author:** ![aether](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aether/32/1338_2.png) [@aether](https://discourse.julialang.org/u/aether)\
**Post date:** [August 24, 2017, 9:00am UTC](https://discourse.julialang.org/t/varargs-function-chaining/5534/5 "2017-08-24T09:00:17Z")

</div>

I see it now. Thanks again.
