Permalink
Browse files

Rename collude to knit, make it take vector instead of varargs

  • Loading branch information...
1 parent b6d7072 commit 1ec46c45afb225c0f2da1c17ec5a8b901f2e4ab8 @amalloy amalloy committed Nov 4, 2011
Showing with 7 additions and 6 deletions.
  1. +4 −4 src/useful/fn.clj
  2. +3 −2 test/useful/fn_test.clj
View
8 src/useful/fn.clj
@@ -63,13 +63,13 @@
(fn [& args]
(every? #(apply % args) preds)))
-(defn collude
+(defn knit
"Takes a list of functions (f1 f2 ... fn) and returns a new function F. F takes
- n arguments (x1 x2 ... xn) and returns the list ((f1 x1) (f2 x2) ... (fn xn)).
+ a collection of size n (x1 x2 ... xn) and returns the list ((f1 x1) (f2 x2) ... (fn xn)).
Similar to Haskell's ***, and a nice complement to juxt (which is Haskell's &&&)."
[& fs]
- (fn [& args]
- (map #(% %2) fs args)))
+ (fn [arg-coll]
+ (map #(% %2) fs arg-coll)))
(defn thrush
"Takes the first argument and applies the remaining arguments to it as functions from left to right.
View
5 test/useful/fn_test.clj
@@ -43,9 +43,10 @@
#(zero? (rem % 3)))
(range 11)))))
-(deftest test-collude
+(deftest test-knit
(is (= [5 \t 9]
- ((collude inc last #(* 3 %)) 4 "last" 3))))
+ ((knit inc last #(* 3 %))
+ [4 "last" 3]))))
(deftest test-thrush
(is (= 5 (thrush 1 inc inc inc inc))))

0 comments on commit 1ec46c4

Please sign in to comment.