2014-01-26 00:04:22 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "The map function relates a sequence to another"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= [__ __ __] (map (fn [x] (* 4 x)) [1 2 3]))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "You may create that mapping"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= [1 4 9 16 25] (map (fn [x] __) [1 2 3 4 5]))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Or use the names of existing functions"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= __ (map nil? [:a :b nil :c :d]))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "A filter can be strong"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= __ (filter (fn [x] false) '(:anything :goes :here)))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Or very weak"
|
2011-08-13 17:20:39 +00:00
|
|
|
(= __ (filter (fn [x] true) '(:anything :goes :here)))
|
2010-02-11 04:13:55 +00:00
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Or somewhere in between"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= [10 20 30] (filter (fn [x] __) [10 20 30 40 50 60 70 80]))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Maps and filters may be combined"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= [10 20 30] (map (fn [x] __) (filter (fn [x] __) [1 2 3 4 5 6 7 8])))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Reducing can increase the result"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= __ (reduce (fn [a b] (* a b)) [1 2 3 4]))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "You can start somewhere else"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= 2400 (reduce (fn [a b] (* a b)) __ [1 2 3 4]))
|
|
|
|
|
|
2016-02-27 02:33:05 +00:00
|
|
|
; "Numbers are not the only things one can reduce"
|
2010-02-11 04:13:55 +00:00
|
|
|
(= "longest" (reduce (fn [a b]
|
|
|
|
|
(if (< __ __) b a))
|
2016-02-27 02:33:05 +00:00
|
|
|
["which" "word" "is" "longest"]))
|