Skip to content

Instantly share code, notes, and snippets.

@jackrusher
Created June 1, 2021 12:55
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackrusher/959b35e031fb9b2d30c0211337a310ed to your computer and use it in GitHub Desktop.
Save jackrusher/959b35e031fb9b2d30c0211337a310ed to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment