Multiple named varargs?

I’m wondering whether anyone has already suggested implementing the usage of multiple varargs in functions/methods.

A concrete example I’m thinking about is the following: I have a processing function that I want to make more flexible with pre- and postprocessing. A function with the following signature would come in handy:

function process(a, pre_process..., post_process...)
  for pre in pre_process
   pre()
  end

  do_something()

  for post in post_process
   post()
  end
end

Now I know there are workarounds to this but the syntax above is way more elegant than working with collections. Some way to name the varargs would need to be found though since otherwise there is no way to know which varargs belong to which label.

Maybe it becomes too complex then? Anyway, just a suggestion.

Why not just make pre_process and post_process tuples? That seems a lot simpler than trying to disambiguate which vararg you mean by some other way.

4 Likes