Created
May 14, 2010 20:25
-
-
Save tcrayford/401618 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn my-count [coll] | |
(reduce (fn [n x] (inc n)) 0 coll)) | |
(my-count [1 2 3 3]) | |
(defn my-reverse [coll] ;;only works for vectors atm | |
(reduce (fn [xs x] (into [x] xs)) [] coll)) | |
(my-reverse [1 2 3]) | |
(defn my-map [f coll] ;; | |
(reduce (fn [xs x] (conj xs (f x))) [] coll)) | |
(my-map inc [1 2 3]) | |
(defn my-filter [pred coll] | |
(reduce (fn [xs x] (if (pred x) | |
(conj xs x) | |
xs)) | |
[] | |
coll)) | |
(my-filter even? [1 2 3]) | |
(defn my-binary-comp [f g] | |
(fn [x] (f (g x)))) | |
(defn my-comp [& fs] | |
(reduce my-binary-comp identity fs)) | |
((my-comp inc inc inc) 1) | |
(defn foldl [f value coll] | |
(reduce f value (reverse coll))) | |
(defn my-reverse [coll] | |
(foldl (fn [xs x] (conj xs x)) [] coll)) | |
(my-reverse [1 2 3]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment