about summary refs log tree commit diff stats
path: root/seq-primer.clj
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2023-12-13 13:32:03 -0500
committerelioat <elioat@tilde.institute>2023-12-13 13:32:03 -0500
commit738767daa114003f565d16480be0badc6c4ced0a (patch)
tree97dd1fc630acc151c9c6d88efc586e7744042e65 /seq-primer.clj
parent4035bec450015f8be01bea499ee58236d3a6ab40 (diff)
downloadtour-738767daa114003f565d16480be0badc6c4ced0a.tar.gz
*
Diffstat (limited to 'seq-primer.clj')
-rw-r--r--seq-primer.clj37
1 files changed, 37 insertions, 0 deletions
diff --git a/seq-primer.clj b/seq-primer.clj
new file mode 100644
index 0000000..0f9fe43
--- /dev/null
+++ b/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