4 ms·
Clojure has something that you could call a pipe almost. `->` passes the output from one form to the next one. This example has a nested hash map where we try
by diggan 8y ago
Clojure has something that you could call a pipe almost. `->` passes the output from one form to the next one.
This example has a nested hash map where we try to get the "You got me!" string.
We can either use `:a` (keyword) as a function to get the value. Then we have to nest the function calls a bit unnaturally.
Or we can use the thread-first macro `->`, which is basically a unix pipe.
user=> (def res {:a {:b {:c "You got me!"}}})
#'user/res
user=> res
{:a {:b {:c "You got me!"}}}
user=> (:c (:b (:a res)))
"You got me!"
user=> (-> res :a :b :c)
"You got me!"
Thinking about it, Clojure advocates having small functions (similar to unix's "small programs / do one thing well") that you compose together to build bigger things.
- lincpa 8y agoClojure: The Pure Function Pipeline Data Flow https://github.com/linpengcheng/PurefunctionPipelineDataflow https://github.com/linpengcheng/PurefunctionPipelineDataflow