# Call a function f with a list of arguments for a helper function

**URL:** <https://discourse.julialang.org/t/call-a-function-f-with-a-list-of-arguments-for-a-helper-function/34541>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [February 12, 2020, 8:58pm UTC](https://discourse.julialang.org/t/call-a-function-f-with-a-list-of-arguments-for-a-helper-function/34541 "2020-02-12T20:58:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ea42gh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ea42gh/32/12000_2.png) [@ea42gh](https://discourse.julialang.org/u/ea42gh)\
**Post date:** [February 12, 2020, 8:58pm UTC](https://discourse.julialang.org/t/call-a-function-f-with-a-list-of-arguments-for-a-helper-function/34541/1 "2020-02-12T20:58:27Z")

</div>

I found [Generic function to call arbitrary Julia function and its arguments](https://discourse.julialang.org/t/generic-function-to-call-arbitrary-julia-function-and-its-arguments/25407) but can’t quite figure out how to make this work:

Given a helper `function f(a;b=5,c=10)`, I want to write a `function g( args )` that iterates over args  
and calls f (i.e., folding f over the args).

How do I express this? The args may or may not have all of the optional arguments of `f()`

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 12, 2020, 10:10pm UTC](https://discourse.julialang.org/t/call-a-function-f-with-a-list-of-arguments-for-a-helper-function/34541/2 "2020-02-12T22:10:29Z")

</div>

What is the context? If you have a tuple of arguments, you can just do `g(args; kws...) = f(args...; kws...)`. What actual problem are you trying to solve here?

In the thread you linked, the poster was storing arguments as strings, which is generally a bad idea for many reasons.

---

<div class="post-metadata">

**Author:** ![ea42gh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ea42gh/32/12000_2.png) [@ea42gh](https://discourse.julialang.org/u/ea42gh)\
**Post date:** [February 13, 2020, 10:15pm UTC](https://discourse.julialang.org/t/call-a-function-f-with-a-list-of-arguments-for-a-helper-function/34541/3 "2020-02-13T22:15:01Z")

</div>

Just a utility function in jupyter to output a title:

```julia
function title( txt; sz=25,color="blue",justify="left")
    t = """<br><div style="width:30cm;color:$(color);text-align:$(justify);font-size:$(sz)px;">$(txt)</div>"""
    display(HTML(t))
end

```

The issue was that adding a substring forces calling the function with the title including some html  
(e.g., \<p style="…\>). I wanted to make it easy on myself and the users of my notebooks  
by rewriting the function to take some kind of simple structure that allows multiple instances of text,  
with only some of the default arguments being overridden.

Not valid code, but something resembling: `title( ["A title", ("subtitle", sz=15)] )`

The reason I mentioned folding is that the function would concatenate appropriate html substrings

---

<div class="post-metadata">

**Author:** ![ea42gh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ea42gh/32/12000_2.png) [@ea42gh](https://discourse.julialang.org/u/ea42gh)\
**Post date:** [February 15, 2020, 8:53pm UTC](https://discourse.julialang.org/t/call-a-function-f-with-a-list-of-arguments-for-a-helper-function/34541/4 "2020-02-15T20:53:31Z")

</div>

I ended up with the following

```julia
struct T
    txt ::String
    color ::String
    justify ::String
    sz ::Int
    height ::Int
    f
end

T(txt;sz=20,color="blue",justify="left",height=5) =
    T(txt,color,justify,sz,height,()-> "<p style=\"color:$color;font-size:$(sz)pt;height:$(height)px;text-align:$justify;\">$txt</p>")

title( s :: T) = display(HTML("<div>"* s.f()*"</div>"))
title( txt :: String; sz=25,color="blue",justify="left",height=5) = title( T(txt,sz=sz,color=color,justify=justify,height=height))
title( l :: Array{T} ) = display(HTML("<div>"* reduce( (x,y)->x.f()*y.f(), l )*"</div>"))

```

It can be called with statements like

```julia
title( T("Some text",sz=20) ) # single line output using T()
title( "="^300,sz=3) # single line output
title([ T("s",height=5,sz=25,color="magenta"),
        T("x",sz=15,height=10)]) # multiline output

```

Still clumsy to use! Is there any way to get rid of the constructor for `T`? Or better Julia code?
