|
| 1 | + |
| 2 | +(ns clojure-camp.pairing) |
| 3 | + |
| 4 | +;; let's work on an algorithm together! |
| 5 | + |
| 6 | +;; this produces a lazy sequence of strings: |
| 7 | +(map #(str "Hello, " % "!") ["Alice" "Bob" "Charlie"]) |
| 8 | + |
| 9 | +;; here's the non-lazy transducer-based version: |
| 10 | +(into [] |
| 11 | + (map #(str "Hello, " % "!")) |
| 12 | + ["Alice" "Bob" "Charlie"]) |
| 13 | + |
| 14 | +;; map with a single function argument produces a transducer: |
| 15 | +(map #(str "Hello, " % "!")) |
| 16 | + |
| 17 | +;; we can build up xforms (transformers) using the `comp` function: |
| 18 | +(def xf (comp (filter #(> (count %) 3)) |
| 19 | + (map #(str "Hello, " % "!")))) |
| 20 | + |
| 21 | +;; and now use it with `into`: |
| 22 | +(into [] |
| 23 | + xf ; Bob gets filtered out |
| 24 | + ["Alice" "Bob" "Charlie"]) |
| 25 | + |
| 26 | +;; "traditional" SQL-like rows of columns: |
| 27 | +^:kind/table |
| 28 | +[{:name "Alice" :age 30 :city "Wonderland"} |
| 29 | + {:name "Bob" :age 25 :city "Builderland"} |
| 30 | + {:name "Charlie" :age 35 :city "Chocolate Factory"}] |
| 31 | + |
| 32 | +;; more columnar format: |
| 33 | +^:kind/table |
| 34 | +{:name ["Alice" "Bob" "Charlie"] |
| 35 | + :age [30 25 35] |
| 36 | + :city ["Wonderland" "Builderland" "Chocolate Factory"]} |
| 37 | + |
| 38 | +;; and display it as a portal widget: |
| 39 | +^:kind/portal |
| 40 | +{:name ["Alice" "Bob" "Charlie"] |
| 41 | + :age [30 25 35] |
| 42 | + :city ["Wonderland" "Builderland" "Chocolate Factory"]} |
0 commit comments