Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ _site/
/checkouts
/classes
/target
.calva/repl.calva-repl
.calva/mcp-server/port
.portal/vs-code.edn
42 changes: 42 additions & 0 deletions notebooks/clojure_camp/pairing.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

(ns clojure-camp.pairing)

;; let's work on an algorithm together!

;; this produces a lazy sequence of strings:
(map #(str "Hello, " % "!") ["Alice" "Bob" "Charlie"])

;; here's the non-lazy transducer-based version:
(into []
(map #(str "Hello, " % "!"))
["Alice" "Bob" "Charlie"])

;; map with a single function argument produces a transducer:
(map #(str "Hello, " % "!"))

;; we can build up xforms (transformers) using the `comp` function:
(def xf (comp (filter #(> (count %) 3))
(map #(str "Hello, " % "!"))))

;; and now use it with `into`:
(into []
xf ; Bob gets filtered out
["Alice" "Bob" "Charlie"])

;; "traditional" SQL-like rows of columns:
^:kind/table
[{:name "Alice" :age 30 :city "Wonderland"}
{:name "Bob" :age 25 :city "Builderland"}
{:name "Charlie" :age 35 :city "Chocolate Factory"}]

;; more columnar format:
^:kind/table
{:name ["Alice" "Bob" "Charlie"]
:age [30 25 35]
:city ["Wonderland" "Builderland" "Chocolate Factory"]}

;; and display it as a portal widget:
^:kind/portal
{:name ["Alice" "Bob" "Charlie"]
:age [30 25 35]
:city ["Wonderland" "Builderland" "Chocolate Factory"]}