Permalink
Browse files

Add test for knit; make it return vector

  • Loading branch information...
1 parent 1ec46c4 commit 4d7415855ec311cf6cc85e8e32b732d53d6f703d @amalloy amalloy committed Nov 4, 2011
Showing with 7 additions and 3 deletions.
  1. +2 −2 src/useful/fn.clj
  2. +5 −1 test/useful/fn_test.clj
View
@@ -65,11 +65,11 @@
(defn knit
"Takes a list of functions (f1 f2 ... fn) and returns a new function F. F takes
- a collection of size n (x1 x2 ... xn) and returns the list ((f1 x1) (f2 x2) ... (fn xn)).
+ a collection of size n (x1 x2 ... xn) and returns a vector [(f1 x1) (f2 x2) ... (fn xn)].
Similar to Haskell's ***, and a nice complement to juxt (which is Haskell's &&&)."
[& fs]
(fn [arg-coll]
- (map #(% %2) fs arg-coll)))
+ (vec (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
@@ -46,7 +46,11 @@
(deftest test-knit
(is (= [5 \t 9]
((knit inc last #(* 3 %))
- [4 "last" 3]))))
+ [4 "last" 3])))
+ (is (= {"A" 10 "B" 1}
+ (into {}
+ (map (knit #(.toUpperCase %) inc)
+ {"a" 9 "b" 0})))))
(deftest test-thrush
(is (= 5 (thrush 1 inc inc inc inc))))

0 comments on commit 4d74158

Please sign in to comment.