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

I found Generic function to call arbitrary Julia function and its arguments 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()

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.

1 Like

Just a utility function in jupyter to output a title:

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>"""

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

I ended up with the following

struct T
    txt     ::String
    color   ::String
    justify ::String
    sz      ::Int
    height  ::Int

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

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?