Various collection utilities, mainly those returning either a non-collection result or a non-recipe collection.

Primary

butlast

Available since version 1.0 (view source)

Usage:
  • (butlast coll)

Type signature:
  • ([]) → (Maybe ISeq)

Returns a non-lazy realized sequence of all but last item from coll in linear time.

every?

Available since version 1.0 (view source)

Usage:
  • (every? pred coll)

Type signature:
  • (AnyFn ⨯ []) → Boolean+

Returns true if every item of coll satisfies pred, otherwise returns false.

See also: some, not-any?, not-every?

frequencies

Available since version 1.0 (alias of clojure.core/frequencies)

Usage:
  • (frequencies coll)

Type signature:
  • ([]) → {}

Returns a map from distinct items in coll to the number of times they appear.

See also: group-by

group-by

Available since version 1.0 (alias of clojure.core/group-by)

Usage:
  • (group-by f coll)

Type signature:
  • (AnyFn ⨯ []) → {}

Returns a map of the items of coll keyed by the result of f on each item. The value at each key will be a vector of the corresponding items, in the order they appeared in coll.

See also: frequencies

into

Available since version 1.0 (view source)

Usage:
  • (into coll from)

  • (into coll xform from)

Type signatures:
  • (IPersistentCollection ⨯ []) → IPersistentCollection

  • (IPersistentCollection ⨯ Transducer ⨯ []) → IPersistentCollection

Returns a new coll consisting of coll with all of the items of from conjoined. Prefer cat instead if both collections are of same type and are catenable.

last

Available since version 1.0 (view source)

Usage:
  • (last coll)

Type signature:
  • ([]) → Any

Returns the last item from coll, returning nil if coll is empty. Is linear time at worst.

not-any?

Available since version 1.0 (view source)

Usage:
  • (not-any? pred coll)

Type signature:
  • (AnyFn ⨯ []) → Boolean+

Returns true if no item from coll satisfies pred, otherwise returns false.

See also: some, every?, not-every?

not-every?

Available since version 1.0 (view source)

Usage:
  • (not-every? pred coll)

Type signature:
  • (AnyFn ⨯ []) → Boolean+

Returns true if at least one item from coll does not satisfy pred, otherwise returns false.

See also: some, not-any?, every?

recipe

Available since version 1.0 (alias of dunaj.coll.helper/recipe)

Usage:
  • (recipe xform coll)

Type signature:
  • (AnyFn ⨯ []) → []

Returns a reducible collection which uses xform for reducing coll. Optionally supports fold, section, count, batched and unpacked reduce based on which features are supported by xform and coll.

revlist

Available since version 1.0 (alias of clojure.core/reverse)

Usage:
  • (revlist coll)

Type signature:
  • ([]) → IPersistentList

Returns a seq of the items in coll in reverse order. Not lazy.

Use more performant functions reverse or flip if the input collection supports them.

sequence

Available since version 1.0 (view source)

Usage:
  • (sequence coll)

  • (sequence xform coll)

  • (sequence xform coll & colls)

Type signatures:
  • ([]) → ISeq

  • (Transducer ⨯ []) → ISeq

  • (Transducer ⨯ [] ⨯ (Va [])) → ISeq

Transforms coll to a possibly empty lazy seq, or returns coll if it already is a seq. Will not force lazy seq, nor will reduce any items from coll. Returns empty list if the coll is nil. May supply transducer xform or multiple colls, in which case a multireducible will be created.

shuffle

Available since version 1.0 (view source)

Usage:
  • (shuffle coll)

Type signature:
  • ([]) → []

Returns a random permutation of coll.

See also: sort, sort-by

some

Available since version 1.0 (view source)

Usage:
  • (some pred coll)

Type signature:
  • (AnyFn ⨯ []) → Any

Returns first logical true value of calling pred on items from coll, otherwise returns nil.

See also: every?, not-any?, not-every?

sort

Available since version 1.0 (view source)

Usage:
  • (sort coll)

  • (sort comp coll)

Type signatures:
  • ([]) → []

  • (Function ⨯ []) → []

Returns a sorted collection of the items in coll. If no comparator is supplied, uses natural comparator.

See also: sort-by, shuffle

sort-by

Available since version 1.0 (view source)

Usage:
  • (sort-by keyfn coll)

  • (sort-by keyfn comp coll)

Type signatures:
  • (AnyFn ⨯ []) → []

  • (AnyFn ⨯ Function ⨯ []) → []

Returns a sorted collection of the items in coll, where the sort order is determined by comparing (keyfn item). If no comparator is supplied, uses natural comparator.

See also: sort, shuffle

Iterations

In this section: doall dored dorun doseq for

doall

Available since version 1.0 (view source)

Usage:
  • (doall coll)

  • (doall n coll)

Type signatures:
  • ([]) → (Maybe ISeq)

  • ((Maybe Integer+) ⨯ []) → (Maybe ISeq)

Realizes all or n items in the coll and returns seq to the realized sequence.

See also: dorun, doseq, dored, for

dored

Available since version 1.0 (view source)

MACRO (dored [binding-name xform coll :as bs] & body)

For every value in coll, execute the transducer (optional), and bind the resulting value to the given binding. Prefer this macro over doseq when transducers are in use.

1
2
3
4
5
6
(dored [b xform coll]
  (do-something-with b))

;; can omit transducer
(dored [b coll]
  (do-something-with b))

See also: doall, doseq, for, dorun

dorun

Available since version 1.0 (view source)

Usage:
  • (dorun coll)

  • (dorun n coll)

Type signatures:
  • ([]) → nil

  • ((Maybe Integer+) ⨯ []) → nil

Realizes all or n items from coll, returning nil. Does not hold onto the head of the intermediate sequence.

See also: doall, doseq, dored, for

doseq

Available since version 1.0 (view source)

MACRO (doseq seq-exprs & body)

Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by for. Does not retain the head of the sequence. Returns nil.

See also: doall, for, dored, dorun

for

Available since version 1.0 (alias of clojure.core/for)

MACRO (for seq-exprs body-expr)

List comprehension. Takes a vector of one or more binding-form/collection-expr pairs, each followed by zero or more modifiers, and yields a lazy sequence of evaluations of body-expr. Collections are iterated in a nested fashion, rightmost fastest, and nested coll-exprs can refer to bindings created in prior binding-forms.

Supported modifiers are: :let [binding-form expr …​], :while test and :when test.

1
2
(seq (take 100 (for [x (range 100000000) y (range 1000000) :while (< y x)] [x y])))
;;=> ([1 0] [2 0] [2 1] [3 0] [3 1] [3 2] [4 0] [4 1] [4 2] [4 3] [5 0] [5 1] [5 2] [5 3] [5 4] [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] [7 0] [7 1] [7 2] [7 3] [7 4] [7 5] [7 6] [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] [9 0] [9 1] [9 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8] [10 0] [10 1] [10 2] [10 3] [10 4] [10 5] [10 6] [10 7] [10 8] [10 9] [11 0] [11 1] [11 2] [11 3] [11 4] [11 5] [11 6] [11 7] [11 8] [11 9] [11 10] [12 0] [12 1] [12 2] [12 3] [12 4] [12 5] [12 6] [12 7] [12 8] [12 9] [12 10] [12 11] [13 0] [13 1] [13 2] [13 3] [13 4] [13 5] [13 6] [13 7] [13 8] [13 9] [13 10] [13 11] [13 12] [14 0] [14 1] [14 2] [14 3] [14 4] [14 5] [14 6] [14 7] [14 8])

See also: doall, doseq, dored, dorun

Reducers

batched

Available since version 1.0 (view source)

Usage:
  • (batched coll)

  • (batched requested-type coll)

  • (batched requested-type size-hint coll)

Type signatures:
  • (IRed) → IRed

  • ((U nil Class+ Type) ⨯ IRed) → IRed

  • ((U nil Class+ Type) ⨯ (Maybe Integer+) ⨯ IRed) → IRed

Returns a collection that reduces on batched values.

fold-batched

Available since version 1.0 (view source)

Usage:
  • (fold-batched reducef coll)

  • (fold-batched combinef reducef coll)

  • (fold-batched requested-type size-hint combinef reducef coll)

  • (fold-batched requested-type size-hint n combinef reducef coll)

Type signatures:
  • (AnyFn ⨯ IFoldable) → Any

  • (AnyFn ⨯ AnyFn ⨯ IFoldable) → Any

  • ((U nil Class+ Type) ⨯ (Maybe Integer+) ⨯ AnyFn ⨯ AnyFn ⨯ IFoldable) → Any

  • ((U nil Class+ Type) ⨯ (Maybe Integer+) ⨯ Integer+ ⨯ AnyFn ⨯ AnyFn ⨯ IFoldable) → Any

Folds batched collection.

fold-unpacked

Available since version 1.0 (view source)

Usage:
  • (fold-unpacked reducef coll)

  • (fold-unpacked combinef reducef coll)

  • (fold-unpacked n combinef reducef coll)

Type signatures:
  • (AnyFn ⨯ IFoldable) → Any

  • (AnyFn ⨯ AnyFn ⨯ IFoldable) → Any

  • (Integer+ ⨯ AnyFn ⨯ AnyFn ⨯ IFoldable) → Any

Folds unpacked collection.

not-batchable

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (not-batchable coll)

Type signature:
  • (IRed) → IRed

Returns a collection that is not batchable.

See also: batched, reduce-batched

reduce-batched

Available since version 1.0 (view source)

Usage:
  • (reduce-batched reducef coll)

  • (reduce-batched reducef init coll)

  • (reduce-batched requested-type reducef init coll)

  • (reduce-batched requested-type size-hint reducef init coll)

Type signatures:
  • (AnyFn ⨯ IRed) → Any

  • (AnyFn ⨯ Any ⨯ IRed) → Any

  • ((U nil Class+ Type) ⨯ AnyFn ⨯ Any ⨯ IRed) → Any

  • ((U nil Class+ Type) ⨯ (Maybe Integer+) ⨯ AnyFn ⨯ Any ⨯ IRed) → Any

Reduces coll by batches, creating temporary batches if coll is not batchable.

reduce-unpacked

Available since version 1.0 (view source)

Usage:
  • (reduce-unpacked reducef coll)

  • (reduce-unpacked reducef init coll)

Type signatures:
  • (AnyFn ⨯ []) → Any

  • (AnyFn ⨯ Any ⨯ []) → Any

Reduces coll with unpacked fn reducef. Works on any collection, not just unpackable one.

unpacked

Available since version 1.0 (view source)

Usage:
  • (unpacked coll)

Type signature:
  • (IRed) → IRed

Returns a collection that reduces on unpacked values. Works on any collection, not just on unpackable one.

Maps

keywordize-keys

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (keywordize-keys m)

Type signature:
  • (Any) → Any

Recursively transforms all map keys from strings to keywords.

See also: stringify-keys

map-invert

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (map-invert m)

Type signature:
  • ({}) → {}

Returns the map m with the vals mapped to the keys.

See also: dunaj.coll/invert

merge

Available since version 1.0 (view source)

Usage:
  • (merge)

  • (merge m)

  • (merge m m1)

  • (merge m m1 m2)

  • (merge m m1 m2 & maps)

Type signatures:
  • () → {}

  • ({}) → {}

  • ({} ⨯ {}) → {}

  • ({} ⨯ {} ⨯ {}) → {}

  • ({} ⨯ {} ⨯ {} ⨯ (Va {})) → {}

Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping from the latter (left-to-right) will be the mapping in the result.

merge-with

Available since version 1.0 (alias of clojure.core/merge-with)

Usage:
  • (merge-with f & maps)

Type signature:
  • ((Fn [Any Any Any]) ⨯ (Va {})) → {}

Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with the mapping in the result by calling (f val-in-result val-in-latter).

See also: merge, dunaj.coll/conj

rename-keys

Available since version 1.0 (alias of clojure.set/rename-keys)

not referred automatically

Usage:
  • (rename-keys map kmap)

Type signature:
  • ({} ⨯ {}) → {}

Returns the map with the keys in kmap renamed to the vals in kmap

See also: select-keys

select-keys

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (select-keys map keys)

Type signature:
  • ({} ⨯ []) → {}

Returns a map containing only those entries in map whose key is in keys.

See also: rename-keys

stringify-keys

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (stringify-keys m)

Type signature:
  • (Any) → Any

Recursively transforms all map keys from keywords to strings.

See also: keywordize-keys

Walk

postwalk

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (postwalk f form)

  • (postwalk branch-fn f form)

Type signatures:
  • (AnyFn ⨯ Any) → Any

  • (Predicate ⨯ AnyFn ⨯ Any) → Any

Performs a depth-first, post-order traversal of form. Calls f on each sub-form, uses f’s return value in place of the original.

postwalk-replace

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (postwalk-replace smap form)

  • (postwalk-replace branch-fn smap form)

Type signatures:
  • ({} ⨯ Any) → Any

  • (Predicate ⨯ {} ⨯ Any) → Any

Recursively transforms form by replacing keys in smap with their values. Like replace but works on any data structure. Does replacement at the leaves of the tree first.

prewalk

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (prewalk f form)

  • (prewalk branch-fn f form)

Type signatures:
  • (AnyFn ⨯ Any) → Any

  • (Predicate ⨯ AnyFn ⨯ Any) → Any

Like postwalk, but does pre-order traversal.

prewalk-replace

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (prewalk-replace smap form)

  • (prewalk-replace branch-fn smap form)

Type signatures:
  • ({} ⨯ Any) → Any

  • (Predicate ⨯ {} ⨯ Any) → Any

Recursively transforms form by replacing keys in smap with their values. Like replace but works on any data structure. Does replacement at the root of the tree first.

walk

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (walk inner outer form)

  • (walk branch-fn inner outer form)

Type signatures:
  • (AnyFn ⨯ AnyFn ⨯ Any) → Any

  • (Predicate ⨯ AnyFn ⨯ AnyFn ⨯ Any) → Any

Traverses form, an arbitrary data structure. Applies inner to each item of form, building up a data structure of the same type, then applies outer to the result. Uses branch-fn to determine whether walk should nest or not.

See also: postwalk, prewalk

Other

In this section: macroexpand-all

macroexpand-all

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (macroexpand-all form)

Type signature:
  • (Any) → Any

Recursively performs all possible macroexpansions in form.