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