(def f (partial + 1)) ; => #'user/f
(f 1) ; => 2
>
> -- 2) Anonymous function:
> Prelude> let f2 = \x -> x * 2
> Prelude> f2 2
> 4
(def f2 (fn [x] (* x 2))) ; => #'user/f2
(f2 2) ; => 4
>
> -- 3) Function composition:
> Prelude> (f2 . f) 3
> 8
> Prelude>
((comp f2 f) 3) ; => 8
voila.
Jeff
Or even
(def f2 #(* % 2))
Stuart
When in doubt:
- Clojure native API
<http://clojure.org/api>
- comp
<http://clojure.org/api#toc122>
Randall Schulz
Or:
user=> (doc comp)
-------------------------
clojure.core/comp
([& fs])
Takes a set of functions and returns a fn that is the composition
of those fns. The returned fn takes a variable number of args,
applies the rightmost of fns to the args, the next
fn (right-to-left) to the result, etc.
- J.