Partial functions with variadic args that cannot be created using partial

Hi Everybody,

I’m currently using the new Keyword argument functions now also accept maps in 1.11.0-alpha1 and I’m trying to create partial function for function like this:

(defn my-example
  [x y z & {:keys [foo bar] :or {foo 123} :as opts}]
  ...)

I can’t use partial since I want to define second argument.

I normal situation I’d use function literal like this

(def my-partial-func #(my-example %1 "defined" %2))

But the problem is that opts are variadic so the map would be converted into a sequence.

The only thing I came up with is:

(defn example-partial2
  [x z & {:as opts}]
  (my-example x 20 z opts))

Could you please tell me are there any other ways / clever ways?

Thank you!

Jeff

Sorry that this isn’t really a solution, but probably you’d be better off using an options map, instead of kw arguments…

I’d use the new feature in 1.11 the other way around, to pass option maps to “older-style” functions with kw arguments if I came across them.

1 Like