Address changes to PR adding threading forms
This commit is contained in:
parent
ba141d0fc2
commit
3afe01adc7
3 changed files with 19 additions and 15 deletions
|
|
@ -275,7 +275,8 @@
|
||||||
12
|
12
|
||||||
[1 2 3]]}]
|
[1 2 3]]}]
|
||||||
|
|
||||||
["26_transducers" {"__" [[2 4]
|
["26_transducers" {"__" ['(2 3 4)
|
||||||
|
[2 4]
|
||||||
[2 4]
|
[2 4]
|
||||||
[2 4]
|
[2 4]
|
||||||
6]}]
|
6]}]
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,11 @@
|
||||||
(def a-list-with-maps
|
(def a-list-with-maps
|
||||||
'({:a 1} {:a 2} {:a 3}))
|
'({:a 1} {:a 2} {:a 3}))
|
||||||
|
|
||||||
(defn function-that-takes-a-map [m a b]
|
(defn function-that-takes-a-map [map a b]
|
||||||
(do
|
(get map :a))
|
||||||
(println (str "Other unused arguments: " a " " b))
|
|
||||||
(get m :a)))
|
|
||||||
|
|
||||||
(defn function-that-takes-a-coll [a b coll]
|
(defn function-that-takes-a-coll [a b coll]
|
||||||
(do
|
(map :a coll))
|
||||||
(println (str "Other unused arguments: " a " " b))
|
|
||||||
(map :a coll)))
|
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
"We can use thread first for more readable sequential operations"
|
"We can use thread first for more readable sequential operations"
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,30 @@
|
||||||
(ns koans.26-transducers
|
(ns koans.26-transducers
|
||||||
(:require [koan-engine.core :refer :all]))
|
(:require [koan-engine.core :refer :all]))
|
||||||
|
|
||||||
(def xfms
|
(def example-transducer
|
||||||
|
(map inc))
|
||||||
|
|
||||||
|
(def transforms
|
||||||
(comp (map inc)
|
(comp (map inc)
|
||||||
(filter even?)))
|
(filter even?)))
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
"Consider that sequence operations can be used as transducers"
|
"A sequence operation with only one argument often returns a transducer"
|
||||||
(= __
|
(= __
|
||||||
(transduce xfms conj [1 2 3]))
|
(sequence example-transducer [1 2 3]))
|
||||||
|
|
||||||
|
"Consider that sequence operations can be composed as transducers"
|
||||||
|
(= __
|
||||||
|
(transduce transforms conj [1 2 3]))
|
||||||
|
|
||||||
"We can do this eagerly"
|
"We can do this eagerly"
|
||||||
(= __
|
(= __
|
||||||
(into [] xfms [1 2 3]))
|
(into [] transforms [1 2 3]))
|
||||||
|
|
||||||
"Or lazily"
|
"Or lazily"
|
||||||
(= __
|
(= __
|
||||||
(sequence xfms [1 2 3]))
|
(sequence transforms [1 2 3]))
|
||||||
|
|
||||||
"The transduce function can combine mapping and reduction"
|
"The transduce function can combine mapping and reduction"
|
||||||
(= __
|
(= __
|
||||||
(transduce xfms + [1 2 3])))
|
(transduce transforms + [1 2 3])))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue