diff options
Diffstat (limited to 'clj')
-rw-r--r-- | clj/seq-primer.clj | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/clj/seq-primer.clj b/clj/seq-primer.clj new file mode 100644 index 0000000..0f9fe43 --- /dev/null +++ b/clj/seq-primer.clj @@ -0,0 +1,37 @@ +;; From Jack Rusher +;; https://gist.github.com/jackrusher/959b35e031fb9b2d30c0211337a310ed +;; Condensed visual tutorial in #Bauhaus style for a subset of the #Clojure seq API (inspired by similar JS tweets) + +(def ■ '■) +(def ▲ '▲) +(def ● '●) + +(first [● ■ ▲]) ; ● +(second [● ■ ▲]) ; ■ +(nth [● ■ ▲] 2) ; ▲ +(rest [● ■ ▲]) ; (■ ▲) +(last [● ■ ▲]) ; ▲ +(butlast [● ■ ▲]) ; (● ■) + +(map (partial = ■) [■ ● ■ ▲]) ; (true false true false) + +(filter (partial = ■) [■ ● ■ ▲]) ; (■ ■) +(remove (partial = ■) [■ ● ■ ▲]) ; (● ▲) +(distinct [■ ● ■ ▲ ● ▲]) ; (■ ● ▲) +(interpose '▲ [● ● ●]) ; (● ▲ ● ▲ ●) +(interleave [■ ■ ■] [▲ ▲ ▲] [● ● ●]) ; (■ ▲ ● ■ ▲ ● ■ ▲ ●) + +(take 3 [■ ■ ● ● ▲ ▲]) ; (■ ■ ●) +(take-nth 2 [■ ■ ● ● ▲ ▲ ■ ■]) ; (■ ● ▲ ■) +(take-while (partial = ■) [■ ■ ● ● ▲ ▲ ■ ■]) ; (■ ■) +(drop-while (partial = ■) [■ ■ ● ● ▲ ▲ ■ ■]) ; (● ● ▲ ▲ ■ ■) + +(partition 2 [■ ■ ● ● ▲ ▲ ■ ■]) ; ((■ ■) (● ●) (▲ ▲) (■ ■)) +(partition 2 1 [■ ■ ● ● ▲ ▲ ■ ■]) ; ((■ ■) (■ ●) (● ●) (● ▲) (▲ ▲) (▲ ■) (■ ■)) +(split-at 3 [■ ■ ● ● ▲ ▲ ■ ■]) ; [(■ ■ ●) (● ▲ ▲ ■ ■)] + +(frequencies [■ ■ ● ● ▲ ▲ ■ ■]) ; {■ 4, ● 2, ▲ 2} + +(some (partial = ●) [■ ● ■ ▲]) ; true +(every? (partial = ●) [■ ● ■ ▲]) ; false +(every? (partial = ●) [● ● ●]) ; true |