Jump to content

Clojure Programming/Examples/API Examples/Sequence Operators

From Wikibooks, open books for an open world

interpose

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

interleave

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

reverse

[edit | edit source]
user=> (apply str (interpose " " (reverse (.split "I am cold" " "))))
"cold am I"

butlast

[edit | edit source]
user=> (butlast "hello")
(\h \e \l \l)

replace

[edit | edit source]
(apply str (replace {\l ""} "hello world"))
=> "heo word"