Clojure Programming/Examples/API Examples/Sequence Operators

From Wikibooks, open books for an open world
Jump to: navigation, search

interpose[edit]

user=> (apply str (interpose "|" ["hi" "mum" "and" "dad"]))
"hi|mum|and|dad"

interleave[edit]

user=> (interleave [1 2 3] [:a :b :c])
(1 :a 2 :b 3 :c)

reverse[edit]

user=> (apply str (interpose " " (reverse (.split "I am cold" " "))))
"cold am I"

butlast[edit]

user=> (butlast "hello")
(\h \e \l \l)

replace[edit]

(apply str (replace {\l ""} "hello world"))
=> "heo word"