ClojureDocs

Community-powered documentation and examples for Clojure

Example of the dayclojure.core/partition-by
I think this is a better (more agnostic & more declarative/functional)
arbitrary partitioning. The ratio of true:false can be tweaked for longer
average sequence length.

(defn arbitrarily-partition [coll]
  (let [signals (take (count coll) (cycle [true false]))
        shuffled (shuffle signals)
        zipped (map vector shuffled coll)
        partitioned (partition-by first zipped)]
    (for [c partitioned]
      (map second c))))

;;=> (arbitrarily-partition (range 100))
((0 1) (2) (3) (4 5) (6 7) (8 9 10) (11) (12) (13 14 15) (16) (17 18) (19) (20) (21) (22 23 24 25 26) (27 28) (29) (30 31) (32) (33 34 35 36 37 38) (39 40 41) (42) (43 44 45 46 47) (48 49) (50) (51 52 53) (54) (55 56) (57 58) (59 60 61) (62) (63) (64) (65 66) (67 68) (69) (70) (71) (72 73 74 75) (76) (77 78) (79) (80) (81 82) (83 84 85) (86) (87 88) (89 90 91 92 93) (94) (95 96 97) (98) (99))
Clojure/JVMClojureScriptbabashka
Recently Updated
msyds authored an example for clojure.core/line-seq 21 days ago.
charlot-shaw authored an example for clojure.java.io/resource 128 days ago.
RezendeComZ authored an example for clojure.string/starts-with? 154 days ago.
Contribute to ClojureDocs

Give feedback, add examples, or add link related vars.

Learn how to pitch in →
clojure.core, by purpose
Full quick reference →

Sequences76

seq
Returns a seq on the collection. If the…
sequence
Coerces coll to a (possibly empty)…
eduction
Returns a reducible/iterable…
repeat
Returns a lazy (infinite!, or length n…
replicate
DEPRECATED: Use 'repeat' instead. …
range
Returns a lazy seq of nums from start…
repeatedly
Takes a function of no args, presumably…
iterate
Returns a lazy (infinite!) sequence of…
lazy-seq
Takes a body of expressions that…
lazy-cat
Expands to code which yields a lazy…

Maps26

hash-map
keyval => key val Returns a new hash…
array-map
Constructs an array-map. If any keys…
zipmap
Returns a map with the keys mapped to…
sorted-map
keyval => key val Returns a new…
sorted-map-by
keyval => key val Returns a new…
bean
Takes a Java object and returns a…
frequencies
Returns a map from distinct items in…
assoc
assoc[iate]. When applied to a map,…
assoc-in
Associates a value in a nested…
dissoc
dissoc[iate]. Returns a new map of the…

Vectors10

vec
Creates a new vector containing the…
vector
Creates a new vector containing the…
vector-of
Creates a new vector of a single…
conj
conj[oin]. Returns a new collection…
peek
For a list or queue, same as first, for…
pop
For a list or queue, returns a new…
get
Returns the value mapped to key,…
assoc
assoc[iate]. When applied to a map,…
subvec
Returns a persistent vector of the…
rseq
Returns, in constant time, a seq of the…

Sets7

hash-set
Returns a new hash set with supplied…
set
Returns a set of the distinct elements…
sorted-set
Returns a new sorted set with supplied…
sorted-set-by
Returns a new sorted set with supplied…
conj
conj[oin]. Returns a new collection…
disj
disj[oin]. Returns a new set of the…
get
Returns the value mapped to key,…

clojure.string

Clojure String utilities It is poor form to (:use clojure.string).

splitjoinreplacetrimblank?

clojure.set

Set operations such as union/intersection.

uniondifferenceindexrename-keys

clojure.walk

This file defines a generic tree walker for Clojure data structures.

postwalkprewalkkeywordize-keys

clojure.java.io

This file defines polymorphic I/O utility functions for Clojure.

readerwriterfileresource

clojure.test

A unit testing framework.

deftestistestingare