Collection utilities that return transducers or collection recipes.

Primary

In this section: concat indexed interleave traverse zip

concat

Available since version 1.0 (view source)

Usage:
  • (concat)

  • (concat a)

  • (concat a b)

  • (concat a b & more)

Type signatures:
  • () → []

  • ([]) → []

  • ([] ⨯ []) → []

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

Returns the concatenation of given input collections. Does not support infinite number of arguments.

indexed

Available since version 1.0 (view source)

Usage:
  • (indexed coll)

  • (indexed coll & colls)

Type signatures:
  • ([]) → IRed

  • ([] ⨯ (Va [])) → IRed

Returns a multireducible with (range) as a first collection.

interleave

Available since version 1.0 (view source)

Usage:
  • (interleave)

  • (interleave c1)

  • (interleave c1 & more)

Type signatures:
  • () → []

  • ([]) → []

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

Returns a collection recipe which reduces first item in each coll, then the second etc.

See also: interpose, zip

traverse

Available since version 1.0 (view source)

Usage:
  • (traverse root)

  • (traverse mode root)

  • (traverse branch-fn children-fn root)

  • (traverse mode branch-fn children-fn root)

Type signatures:
  • (Any) → IRed

  • ((U nil Keyword Integer+) ⨯ Any) → IRed

  • (Predicate ⨯ AnyFn ⨯ Any) → IRed

  • ((U nil Keyword Integer+) ⨯ Predicate ⨯ AnyFn ⨯ Any) → IRed

Returns a collection recipe which contains nodes from tree traversion starting at root node, branching if branch-fn returns true, using children-fn to produce children from a branch node. Works with infinite trees.

Depth first search `mode`s:

  • :pre - pre-order

  • :post - post-order

  • :in - in-order

  • N - in-order where the node is visited after N branches are traversed (0 - preorder, 1 - classic inorder)

Breadth first search modes:

  • :level - level order

zip

Available since version 1.0 (view source)

Usage:
  • (zip a b)

  • (zip a b c)

  • (zip a b c & colls)

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

  • ([] ⨯ [] ⨯ []) → IRed

  • ([] ⨯ [] ⨯ [] ⨯ (Va [])) → IRed

Returns multireducible from given colls. Reducing multireducible will reduce on tuple of items.

Use unpacked function to get collection which reduces on individual items.

Generators

In this section: cycle iterate range repeat repeatedly

cycle

Available since version 1.0 (view source)

Usage:
  • (cycle coll)

Type signature:
  • ([]) → IRed

Returns an infinite collection of repetitions of the items in coll.

See also: repeat, range

iterate

Available since version 1.0 (view source)

Usage:
  • (iterate f x)

  • (iterate type f x)

Type signatures:
  • (AnyFn ⨯ Any) → IRed

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

Returns a collection of x, (f x), (f (f x)) etc. f must be free of side-effects. For primitive collections, type can be supplied as first arg.

See also: repeatedly, repeat

range

Available since version 1.0 (view source)

Usage:
  • (range)

  • (range end)

  • (range start end)

  • (range start end step)

  • (range type start end step)

Type signatures:
  • () → IRed

  • ((Maybe Number+)) → IRed

  • (Number+ ⨯ (Maybe Number+)) → IRed

  • (Number+ ⨯ (Maybe Number+) ⨯ Number+) → IRed

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

Returns a collection recipe containing numbers from start to end, with given step.

Optionally supports primitive data types and batched reduce when type is specified.

Implementation note: The implementation incrementally adds step amount, which is faster than using multiplication, but precision is gradualy lost if using floating point step.

See also: repeat, cycle

repeat

Available since version 1.0 (view source)

Usage:
  • (repeat val)

  • (repeat n val)

  • (repeat type n val)

Type signatures:
  • (Any) → IRed

  • ((Maybe Integer+) ⨯ Any) → IRed

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

Returns a collection of val-s (infinite, or length n if supplied). For primitive collections, type can be supplied as an additional argument.

See also: range, cycle

repeatedly

Available since version 1.0 (view source)

Usage:
  • (repeatedly f)

  • (repeatedly n f)

  • (repeatedly type n f)

Type signatures:
  • (AnyFn) → IRed

  • ((Maybe Integer+) ⨯ AnyFn) → IRed

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

Returns a (infinite!, or length n if supplied) collection of calls to f. For primitive collections, type can be supplied as additional arg.

Be aware that batched reduce may call f more times than requested.

See also: repeat, range, cycle

Transducers

append

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (append x)

  • (append x coll)

Type signatures:
  • (Any) → Transducer

  • (Any ⨯ []) → IRed

Returns a transducer that 'appends' val, passing it after all step values are processed.

append-coll

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (append-coll xs)

  • (append-coll xs coll)

Type signatures:
  • ([]) → Transducer

  • ([] ⨯ []) → IRed

Returns a transducer that 'appends' coll, passing its values after all step values are processed.

cap

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (cap n tail)

  • (cap n tail coll)

Type signatures:
  • (Int ⨯ IRed) → Transducer

  • (Int ⨯ IRed ⨯ []) → IRed

Returns a transducer that passes values from tail after passing n step values. Tail is not passed if less than n step values were passed.

capped-drop-while

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (capped-drop-while n pred)

  • (capped-drop-while n pred coll)

Type signatures:
  • (Int ⨯ Predicate) → Transducer

  • (Int ⨯ Predicate ⨯ []) → IRed

Returns a transducer that drops step values while they satisfies predicate pred. Throws after more than n items are dropped.

See also: drop-while

concat*

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (concat*)

  • (concat* xs)

Type signatures:
  • () → Transducer

  • (Any) → Transducer

Returns a transducer which concatenates step values.

dedupe

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (dedupe)

  • (dedupe coll)

Type signatures:
  • () → Transducer

  • ([]) → IRed

Returns a transducer that filters out consecutive duplicate step values.

See also: distinct, filter, keep, remove

distinct

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (distinct)

  • (distinct coll)

Type signatures:
  • () → Transducer

  • ([]) → IRed

Returns a transducer that passes only unique step values.

See also: dedupe, filter, keep

drop

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (drop n)

  • (drop n coll)

Type signatures:
  • (Int) → Transducer

  • (Int ⨯ []) → IRed

Returns a transducer that drops n first step values.

See also: drop-while, drop-last, take

drop-last

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (drop-last n)

  • (drop-last n coll)

Type signatures:
  • (Int) → Transducer

  • (Int ⨯ []) → IRed

Returns a transducer that passes all but last n step values.

See also: take-last, drop, drop-while

drop-while

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (drop-while pred)

  • (drop-while pred coll)

Type signatures:
  • (Predicate) → Transducer

  • (Predicate ⨯ []) → IRed

Returns a transducer that drops step values while they satisfies predicate pred.

filter

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (filter pred)

  • (filter pred coll)

Type signatures:
  • (Predicate) → Transducer

  • (Predicate ⨯ []) → IRed

Returns a transducer that pass only those step values which satisfies predicate pred

See also: map, remove, keep, mapcat, replace

flatten

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (flatten)

  • (flatten coll)

  • (flatten pred coll)

Type signatures:
  • () → Transducer

  • ((U nil IRed (I Function Predicate))) → IRed

  • ((Maybe Predicate) ⨯ []) → IRed

Returns a transducer that flattens step values, using predicate pred to determine whether to flatten the value or not.

See also: flatten*

flatten*

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (flatten* pred)

  • (flatten* pred coll)

Type signatures:
  • (Predicate) → Transducer

  • (Predicate ⨯ []) → IRed

Returns a transducer that flattens step values, using predicate pred to determine whether to flatten the value or not.

See also: flatten

foldable-lines

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (foldable-lines)

  • (foldable-lines coll)

Type signatures:
  • () → Transducer

  • ([]) → IRed

Returns a transducer for foldable-only line splitting.

See also: lines

foldable-partition-by*

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (foldable-partition-by* f ir)

  • (foldable-partition-by* f ir coll)

Type signatures:
  • (AnyFn ⨯ IReducing) → Transducer

  • (AnyFn ⨯ IReducing ⨯ []) → IRed

Returns a transducer for foldable-only partition-by.

interpose

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (interpose sep)

  • (interpose sep coll)

Type signatures:
  • (Any) → Transducer

  • (Any ⨯ []) → IRed

Returns a transducer that passes sep value between step values.

See also: interleave

keep

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (keep mapf)

  • (keep mapf coll)

Type signatures:
  • (AnyFn) → Transducer

  • (AnyFn ⨯ []) → IRed

Returns a transducer that applies mapf to each step value and pass only non-nil results.

See also: map, filter, remove, mapcat

keys

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (keys)

  • (keys coll)

Type signatures:
  • () → Transducer

  • ([]) → IRed

Returns a transducer that treats step values as pairs and passes only the first item of such pair.

lines

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (lines)

  • (lines coll)

Type signatures:
  • () → Transducer

  • ([]) → IRed

Returns a transducer which transform step values into string lines, splitting when newline is encountered. Last trailing newline is ignored, if present. Recognizes both LF and CR+LF newlines.

map

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (map mapf)

  • (map mapf coll)

Type signatures:
  • (AnyFn) → Transducer

  • (AnyFn ⨯ []) → IRed

Returns a transducer that applies mapf to each step value.

See also: mapcat, filter, remove, flatten, keep

mapcat

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (mapcat mapcatf)

  • (mapcat mapcatf coll)

Type signatures:
  • (AnyFn) → Transducer

  • (AnyFn ⨯ []) → IRed

Returns a transducer that applies mapcatf to each step value and concatenates the results.

See also: map, concat*, keep, flatten, filter, remove

partition

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (partition n)

  • (partition n coll)

  • (partition n step coll)

  • (partition n step pad coll)

  • (partition n step icombinef ireducef coll)

  • (partition n step pad icombinef ireducef coll)

Type signatures:
  • (Integer+) → Transducer

  • (Integer+ ⨯ []) → IRed

  • (Integer+ ⨯ Integer+ ⨯ []) → IRed

  • (Integer+ ⨯ Integer+ ⨯ (U nil true IRed) ⨯ []) → IRed

  • (Integer+ ⨯ Integer+ ⨯ AnyFn ⨯ AnyFn ⨯ []) → IRed

  • (Integer+ ⨯ Integer+ ⨯ (U nil true IRed) ⨯ AnyFn ⨯ AnyFn ⨯ []) → IRed

Returns a transducers for partitions, splitting each step steps, each partition having n items passed in. Individual partitions are constructed with ir augmented reducing function. pad may be nil (only complete partitions), true (returns all unfinished partitions) or a collection (pad and return first unfinished partition).

partition*

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (partition* n step pad ir)

  • (partition* n step pad ir coll)

Type signatures:
  • (Int ⨯ Int ⨯ (U nil true IRed) ⨯ IReducing) → Transducer

  • (Int ⨯ Int ⨯ (U nil true IRed) ⨯ IReducing ⨯ []) → IRed

Returns a transducers for partitions, splitting each step steps, each partition having n items passed in. Individual partitions are constructed with ir augmented reducing function. pad may be nil (only complete partitions), true (returns all unfinished partitions) or a collection (pad and return first unfinished partition).

partition-all

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (partition-all n)

  • (partition-all n coll)

  • (partition-all n step coll)

  • (partition-all n step icombinef ireducef coll)

Type signatures:
  • (Integer+) → Transducer

  • (Integer+ ⨯ []) → IRed

  • (Integer+ ⨯ Integer+ ⨯ []) → IRed

  • (Integer+ ⨯ Integer+ ⨯ AnyFn ⨯ AnyFn ⨯ []) → IRed

Returns a transducers for partitions, splitting each step steps, each partition having n items passed in. Individual partitions are constructed with ir augmented reducing function. Returns all unfinished partitions.

partition-by

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (partition-by f)

  • (partition-by f coll)

  • (partition-by f ireducef coll)

  • (partition-by f icombinef ireducef coll)

Type signatures:
  • (AnyFn) → Transducer

  • (AnyFn ⨯ []) → IRed

  • (AnyFn ⨯ AnyFn ⨯ []) → IRed

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

Returns collection of partitions which are split each time f returns new value. Individual partitions are created with icombinef and ireducef functions.

partition-by*

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (partition-by* f ir)

  • (partition-by* f ir coll)

Type signatures:
  • (AnyFn ⨯ IReducing) → Transducer

  • (AnyFn ⨯ IReducing ⨯ []) → IRed

Returns a transducer for reducible-only partition-by.

prepend

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (prepend x)

  • (prepend x coll)

Type signatures:
  • (Any) → Transducer

  • (Any ⨯ []) → IRed

Returns a transducer that 'prepends' val, passing it after all step values are processed.

prepend-coll

Available since version 1.0 (view source)

not referred automatically

RETURNS TRANSDUCER

Usage:
  • (prepend-coll xs)

  • (prepend-coll xs coll)

Type signatures:
  • ([]) → Transducer

  • ([] ⨯ []) → IRed

Returns a transducer that 'prepends' coll, passing its values after all step values are processed.

reductions

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (reductions f)

  • (reductions f init)

  • (reductions f init coll)

Type signatures:
  • (AnyFn) → Transducer

  • (AnyFn ⨯ Any) → Transducer

  • (AnyFn ⨯ Any ⨯ []) → IRed

Returns a transducer that passes intermediate results of the reduction of step values by f, starting with init which defaults to (f).

remove

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (remove pred)

  • (remove pred coll)

Type signatures:
  • (Predicate) → Transducer

  • (Predicate ⨯ []) → IRed

Returns a transducer that removes those step values which satisfies predicate pred

See also: map, filter, keep, mapcat, replace

replace

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (replace m)

  • (replace m coll)

Type signatures:
  • ({}) → Transducer

  • ({} ⨯ []) → IRed

Returns a transducer that replaces any step values which equal to the key in map m with the respective val from m.

take

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (take n)

  • (take n coll)

Type signatures:
  • (Int) → Transducer

  • (Int ⨯ []) → IRed

Returns a transducer that passes at most n step values.

take-last

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (take-last n)

  • (take-last n coll)

Type signatures:
  • (Int) → Transducer

  • (Int ⨯ []) → IRed

Returns a transducer that passes at most last n step values.

take-nth

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (take-nth n)

  • (take-nth n coll)

Type signatures:
  • (Int) → Transducer

  • (Int ⨯ []) → IRed

Returns a transducer that passes every n-th step values, starting with first one.

See also: take, drop, partition

take-while

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (take-while pred)

  • (take-while pred coll)

Type signatures:
  • (Predicate) → Transducer

  • (Predicate ⨯ []) → IRed

Returns a transducer that pass step values while they satisfies predicate pred.

throwing-cap

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (throwing-cap n)

  • (throwing-cap n coll)

Type signatures:
  • (Int) → Transducer

  • (Int ⨯ []) → IRed

Returns a transducer that throws if more than n step values are passed.

See also: cap, capped-drop-while

vals

Available since version 1.0 (view source)

RETURNS TRANSDUCER

Usage:
  • (vals)

  • (vals coll)

Type signatures:
  • () → Transducer

  • ([]) → IRed

Returns a transducer that treats step values as pairs and passes the second item of such pair.

Other

empty-recipe

Available since version 1.0 (view source)

not referred automatically

VAR of type IRed

An empty recipe.

See also: throwing-recipe

split-at

Available since version 1.0 (view source)

Usage:
  • (split-at n coll)

Type signature:
  • (Integer+ ⨯ IRed) → []

Returns a vector of [(take n coll) (drop n coll)].

See also: split-with, take, drop

split-with

Available since version 1.0 (view source)

Usage:
  • (split-with pred coll)

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

Returns a vector of [(take-while pred coll) (drop-while pred coll)].

throwing-recipe

Available since version 1.0 (view source)

not referred automatically

Usage:
  • (throwing-recipe m)

Type signature:
  • ((Maybe String+)) → IRed

Returns a collection recipe which throws if any attempt to reduce it is performed.

See also: empty-recipe