Guest User


a guest
Apr 2nd, 2018
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. boot.user=> (source partial)
  2. (defn partial
  3.   "Takes a function f and fewer than the normal arguments to f, and
  4.  returns a fn that takes a variable number of additional args. When
  5.  called, the returned function calls f with args + additional args."
  6.   {:added "1.0"
  7.    :static true}
  8.   ([f] f)
  9.   ([f arg1]
  10.    (fn
  11.      ([] (f arg1))
  12.      ([x] (f arg1 x))
  13.      ([x y] (f arg1 x y))
  14.      ([x y z] (f arg1 x y z))
  15.      ([x y z & args] (apply f arg1 x y z args))))
  16.   ([f arg1 arg2]
  17.    (fn
  18.      ([] (f arg1 arg2))
  19.      ([x] (f arg1 arg2 x))
  20.      ([x y] (f arg1 arg2 x y))
  21.      ([x y z] (f arg1 arg2 x y z))
  22.      ([x y z & args] (apply f arg1 arg2 x y z args))))
  23.   ([f arg1 arg2 arg3]
  24.    (fn
  25.      ([] (f arg1 arg2 arg3))
  26.      ([x] (f arg1 arg2 arg3 x))
  27.      ([x y] (f arg1 arg2 arg3 x y))
  28.      ([x y z] (f arg1 arg2 arg3 x y z))
  29.      ([x y z & args] (apply f arg1 arg2 arg3 x y z args))))
  30.   ([f arg1 arg2 arg3 & more]
  31.    (fn [& args] (apply f arg1 arg2 arg3 (concat more args)))))
  32. nil
Add Comment
Please, Sign In to add comment