Some library functions are very amenable to currying; reduce, filter
and map all come to mind.
Here's a patch that implements partial application for reduce, for instance:
Index: src/clj/clojure/boot.clj
===================================================================
--- src/clj/clojure/boot.clj (revision 1064)
+++ src/clj/clojure/boot.clj (working copy)
@@ -503,7 +503,10 @@
is returned and f is not called. If val is supplied, returns the
result of applying f to val and the first item in coll, then
applying f to that result and the 2nd item, etc. If coll contains no
- items, returns val and f is not called."
+ items, returns val and f is not called. If only f is supplied, then
+ a partial application of reduce curried with f is returned."
+ ([f]
+ (fn [& args] (apply reduce f args)))
([f coll]
(let [s (seq coll)]
(if s
This allows for some, in my opinion, very clean code. The simplest
example would be how this allows us to define a sum function:
(def sum (reduce +))
What do you guys think?
--
Venlig hilsen / Kind regards,
Christian Vest Hansen.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---