25
This commit is contained in:
parent
475b2bea94
commit
2f1fa3cc3b
1 changed files with 13 additions and 12 deletions
|
|
@ -15,23 +15,23 @@
|
||||||
|
|
||||||
(meditations
|
(meditations
|
||||||
"We can use thread first for more readable sequential operations"
|
"We can use thread first for more readable sequential operations"
|
||||||
(= __
|
(= {:a 1}
|
||||||
(-> {}
|
(-> {}
|
||||||
(assoc :a 1)))
|
(assoc :a 1)))
|
||||||
|
|
||||||
"Consider also the case of strings"
|
"Consider also the case of strings"
|
||||||
(= __
|
(= "Hello world, and moon, and stars"
|
||||||
(-> "Hello world"
|
(-> "Hello world"
|
||||||
(str ", and moon")
|
(str ", and moon")
|
||||||
(str ", and stars")))
|
(str ", and stars")))
|
||||||
|
|
||||||
"When a function has no arguments to partially apply, just reference it"
|
"When a function has no arguments to partially apply, just reference it"
|
||||||
(= __
|
(= "String with a trailing space"
|
||||||
(-> "String with a trailing space "
|
(-> "String with a trailing space "
|
||||||
clojure.string/trim))
|
clojure.string/trim))
|
||||||
|
|
||||||
"Most operations that take a scalar value as an argument can be threaded-first"
|
"Most operations that take a scalar value as an argument can be threaded-first"
|
||||||
(= __
|
(= 6
|
||||||
(-> {}
|
(-> {}
|
||||||
(assoc :a 1)
|
(assoc :a 1)
|
||||||
(assoc :b 2)
|
(assoc :b 2)
|
||||||
|
|
@ -41,18 +41,18 @@
|
||||||
(get-in [:c :e])))
|
(get-in [:c :e])))
|
||||||
|
|
||||||
"We can use functions we have written ourselves that follow this pattern"
|
"We can use functions we have written ourselves that follow this pattern"
|
||||||
(= __
|
(= 1
|
||||||
(-> {}
|
(-> {}
|
||||||
(assoc :a 1)
|
(assoc :a 1)
|
||||||
(function-that-takes-a-map "hello" "there")))
|
(function-that-takes-a-map "hello" "there")))
|
||||||
|
|
||||||
"We can also thread last using ->>"
|
"We can also thread last using ->>"
|
||||||
(= __
|
(= '(2 3 4)
|
||||||
(->> [1 2 3]
|
(->> [1 2 3]
|
||||||
(map inc)))
|
(map inc)))
|
||||||
|
|
||||||
"Most operations that take a collection can be threaded-last"
|
"Most operations that take a collection can be threaded-last"
|
||||||
(= __
|
(= 12
|
||||||
(->> a-list
|
(->> a-list
|
||||||
(map inc)
|
(map inc)
|
||||||
(filter even?)
|
(filter even?)
|
||||||
|
|
@ -60,7 +60,8 @@
|
||||||
(reduce +)))
|
(reduce +)))
|
||||||
|
|
||||||
"We can use functions we have written ourselves that follow this pattern"
|
"We can use functions we have written ourselves that follow this pattern"
|
||||||
(= __
|
(= [1 2 3]
|
||||||
(->> a-list-with-maps
|
(->> a-list-with-maps
|
||||||
(function-that-takes-a-coll "hello" "there")
|
(function-that-takes-a-coll "hello" "there")
|
||||||
(into []))))
|
(into [])
|
||||||
|
)))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue