Use map/filter/reduce and friends to build readable data pipelines; most sequence transforms are lazy.
Sequence operations are the Clojure equivalent of “collection pipelines” (similar in spirit to Java Streams), but they’re just ordinary functions—and they work across lists, vectors, sets, map entries, and more.
The most common shape is:
mapfilterreduce 1(def orders
2 [{:id 1 :paid? true :total-cents 1200}
3 {:id 2 :paid? false :total-cents 500}
4 {:id 3 :paid? true :total-cents 300}])
5
6(->> orders
7 (filter :paid?)
8 (map :total-cents)
9 (reduce + 0))
10;; => 1500
map — apply a function to each elementmapcat — map + concat (useful for “expand each item into many”)keep — like map, but drops nil resultsfilter / remove — keep or drop elements matching a predicatesome — returns the first truthy value produced by a predicateevery? — all elements satisfy a predicate?take / drop — grab the first N / skip the first Npartition — chunk into fixed-size groupsgroup-by — build a map from a key-function to a collection of itemsreduce — fold a sequence into a single valuefrequencies — counts occurrences of itemsMost sequence transforms (map, filter, remove, take, drop, etc.) are lazy: they do work only when someone consumes the result.
Rule of thumb for Java developers:
map/filterdoseq or run!