We can make Michaล Marczyk answer neater using an agreement in which there are many main functions - you get the default value or identifier, calling the function without arguments, Examples:
(+) ;=> 0 (concat) ;=> ()
Code becomes
(defn map-ext [f & seqs] (lazy-seq (when (some seq seqs) (cons (apply f (map
I have made minimal changes. It can be accelerated a little.
We may need a function that will introduce such a default value into a function that does not have this.
(defn with-default [f default] (fn ([] default) ([& args] (apply f args)))) ((with-default + 6)) ;=> 6 ((with-default + 6) 7 8) ;=> 15
It can be accelerated or even turned into a macro.
source share