Default implementations for basic collection types.

This namespace assigns default implementations for commonly used collection types.

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
(ns foo.bar
  (:api dunaj)
  (:require [dunaj.coll :refer [->collection collection ->convolution convolution]]
            [dunaj.string :refer [lower-case]]
            [dunaj.coll.default :refer [map-factory lst-factory sorted-map-factory]]))

;;; constructors

(->vec 1 2 3 4 5)
;;=> [1 2 3 4 5]

(lst [1 2 3 4 5])
;;=> (1 2 3 4 5)

(->vec-of :byte 1 2 3 4 5)
;;=> [1 2 3 4 5]

(sorted-set [:c :a :b])
;;=> #{:a :b :c}

(defn custom-comparator :- Integer
  "Returns a case insensitive comparator for named objects."
  [x :- INamed, y :- INamed]
  (compare (lower-case (name x)) (lower-case (name y))))
;;=> #'foo.bar/custom-comparator

(->sorted-map :b 1 :a 2 :C 3)
;;=> {:C 3, :a 2, :b 1}

(->sorted-map-by custom-comparator :b 1 :a 2 :C 3)
;;=> {:a 2, :b 1, :C 3}


;;; using empty collections

(conj empty-set :a :b :c)
;;=> #{:c :b :a}

(into empty-que [1 2 3 4 5])
;;=> #<PersistentQueue clojure.lang.PersistentQueue@1c3e4a2>

(assoc (empty-sorted-map) :a 1 :b 2 :C 3)
;;=> {:C 3, :a 1, :b 2}


;;; using factories

(->collection map-factory [:a 1] [:b 2] [:c 3])
;;=> {:c 3, :b 2, :a 1}

(collection lst-factory [1 2 3 4 5])
;;=> (1 2 3 4 5)

(->convolution (assoc sorted-map-factory :comparator custom-comparator) :a 1 :b 2 :C 3)
;;=> {:a 1, :b 2, :C 3}

(convolution sorted-map-factory [:a :b :C] [1 2 3])
;;=> {:C 3, :a 1, :b 2}

Primary

→lst

Available since version 1.0 (view source)

Usage:
  • (->lst)

  • (->lst a)

  • (->lst a b)

  • (->lst a b c)

  • (->lst a b c d)

  • (->lst a b c d & more)

Type signatures:
  • () → IPersistentList

  • (Any) → IPersistentList

  • (Any ⨯ Any) → IPersistentList

  • (Any ⨯ Any ⨯ Any) → IPersistentList

  • (Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentList

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → IPersistentList

Returns a list containing given items, if any.

See also: lst, empty-lst, lst-factory

→map

Available since version 1.0 (view source)

Usage:
  • (->map)

  • (->map key val)

  • (->map key1 val1 key2 val2)

  • (->map key1 val1 key2 val2 key3 val3)

  • (->map key1 val1 key2 val2 key3 val3 key4 val4)

  • (->map key1 val1 key2 val2 key3 val3 key4 val4 & more)

Type signatures:
  • () → IPersistentMap

  • (Any ⨯ Any) → IPersistentMap

  • (Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentMap

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentMap

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentMap

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → IPersistentMap

Returns a map containing given keyvals, if any.

See also: zipmap

→que

Available since version 1.0 (view source)

Usage:
  • (->que)

  • (->que a)

  • (->que a b)

  • (->que a b c)

  • (->que a b c d)

  • (->que a b c d & more)

Type signatures:
  • () → IPersistentList

  • (Any) → IPersistentList

  • (Any ⨯ Any) → IPersistentList

  • (Any ⨯ Any ⨯ Any) → IPersistentList

  • (Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentList

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → IPersistentList

Returns a queue containing given items, if any.

See also: que, empty-que, que-factory

→set

Available since version 1.0 (view source)

Usage:
  • (->set)

  • (->set a)

  • (->set a b)

  • (->set a b c)

  • (->set a b c d)

  • (->set a b c d & more)

Type signatures:
  • () → IPersistentSet

  • (Any) → IPersistentSet

  • (Any ⨯ Any) → IPersistentSet

  • (Any ⨯ Any ⨯ Any) → IPersistentSet

  • (Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentSet

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → IPersistentSet

Returns a set containing given items, if any.

See also: set, empty-set, set-factory

→sorted-map

Available since version 1.0 (view source)

Usage:
  • (->sorted-map)

  • (->sorted-map key val)

  • (->sorted-map key1 val1 key2 val2)

  • (->sorted-map key1 val1 key2 val2 key3 val3)

  • (->sorted-map key1 val1 key2 val2 key3 val3 key4 val4)

  • (->sorted-map key1 val1 key2 val2 key3 val3 key4 val4 & more)

Type signatures:
  • () → (I ISorted IPersistentMap)

  • (Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → (I ISorted IPersistentMap)

Returns a sorted map containing given keyvals, if any, using default item ordering.

→sorted-map-by

Available since version 1.0 (view source)

Usage:
  • (->sorted-map-by comparator)

  • (->sorted-map-by comparator key val)

  • (->sorted-map-by comparator key1 val1 key2 val2)

  • (->sorted-map-by comparator key1 val1 key2 val2 key3 val3)

  • (->sorted-map-by comparator key1 val1 key2 val2 key3 val3 key4 val4)

  • (->sorted-map-by comparator key1 val1 key2 val2 key3 val3 key4 val4 & more)

Type signatures:
  • (Function) → (I ISorted IPersistentMap)

  • (Function ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Function ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Function ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Function ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentMap)

  • (Function ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → (I ISorted IPersistentMap)

Returns the sorted map containing given keyvals, if any, sorted with comparator.

→sorted-set

Available since version 1.0 (view source)

Usage:
  • (->sorted-set)

  • (->sorted-set a)

  • (->sorted-set a b)

  • (->sorted-set a b c)

  • (->sorted-set a b c d)

  • (->sorted-set a b c d & more)

Type signatures:
  • () → (I ISorted IPersistentSet)

  • (Any) → (I ISorted IPersistentSet)

  • (Any ⨯ Any) → (I ISorted IPersistentSet)

  • (Any ⨯ Any ⨯ Any) → (I ISorted IPersistentSet)

  • (Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentSet)

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → (I ISorted IPersistentSet)

Returns a sorted set containing given items, if any, using default item ordering.

→sorted-set-by

Available since version 1.0 (view source)

Usage:
  • (->sorted-set-by comparator)

  • (->sorted-set-by comparator a)

  • (->sorted-set-by comparator a b)

  • (->sorted-set-by comparator a b c)

  • (->sorted-set-by comparator a b c d)

  • (->sorted-set-by comparator a b c d & more)

Type signatures:
  • (Function) → (I ISorted IPersistentSet)

  • (Function ⨯ Any) → (I ISorted IPersistentSet)

  • (Function ⨯ Any ⨯ Any) → (I ISorted IPersistentSet)

  • (Function ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentSet)

  • (Function ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I ISorted IPersistentSet)

  • (Function ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → (I ISorted IPersistentSet)

Returns a sorted set with custom comparator containing given items, if any.

→vec

Available since version 1.0 (view source)

Usage:
  • (->vec)

  • (->vec a)

  • (->vec a b)

  • (->vec a b c)

  • (->vec a b c d)

  • (->vec a b c d & more)

Type signatures:
  • () → IPersistentVector

  • (Any) → IPersistentVector

  • (Any ⨯ Any) → IPersistentVector

  • (Any ⨯ Any ⨯ Any) → IPersistentVector

  • (Any ⨯ Any ⨯ Any ⨯ Any) → IPersistentVector

  • (Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → IPersistentVector

Returns a vector containing given items, if any.

See also: vec, empty-vec, vec-factory

→vec-of

Available since version 1.0 (view source)

Usage:
  • (->vec-of t)

  • (->vec-of t a)

  • (->vec-of t a b)

  • (->vec-of t a b c)

  • (->vec-of t a b c d)

  • (->vec-of t a b c d & more)

Type signatures:
  • ((U nil Class+ Type Keyword)) → (I IHomogeneous IPersistentVector)

  • ((U nil Class+ Type Keyword) ⨯ Any) → (I IHomogeneous IPersistentVector)

  • ((U nil Class+ Type Keyword) ⨯ Any ⨯ Any) → (I IHomogeneous IPersistentVector)

  • ((U nil Class+ Type Keyword) ⨯ Any ⨯ Any ⨯ Any) → (I IHomogeneous IPersistentVector)

  • ((U nil Class+ Type Keyword) ⨯ Any ⨯ Any ⨯ Any ⨯ Any) → (I IHomogeneous IPersistentVector)

  • ((U nil Class+ Type Keyword) ⨯ Any ⨯ Any ⨯ Any ⨯ Any ⨯ (Va Any)) → (I IHomogeneous IPersistentVector)

Returns a primitive vector of type t containing given items, if any.

lst

Available since version 1.0 (view source)

Usage:
  • (lst coll)

Type signature:
  • ([]) → IPersistentList

Returns a list with contents of coll.

que

Available since version 1.0 (view source)

Usage:
  • (que coll)

Type signature:
  • ([]) → IPersistentList

Returns a queue with contents of coll.

set

Available since version 1.0 (view source)

Usage:
  • (set coll)

Type signature:
  • ([]) → IPersistentSet

Returns a set with contents of coll.

sorted-set

Available since version 1.0 (view source)

Usage:
  • (sorted-set coll)

Type signature:
  • ([]) → (I ISorted IPersistentSet)

Returns a sorted set with contents of coll, using default item ordering.

sorted-set-by

Available since version 1.0 (view source)

Usage:
  • (sorted-set-by comparator coll)

Type signature:
  • (Function ⨯ []) → (I ISorted IPersistentSet)

Returns a sorted set with contents of coll and a custom comparator.

sorted-zipmap

Available since version 1.0 (view source)

Usage:
  • (sorted-zipmap keys vals)

Type signature:
  • ([] ⨯ []) → (I ISorted IPersistentMap)

Returns a sorted map with convoluted contents of keys and vals, using default item ordering.

sorted-zipmap-by

Available since version 1.0 (view source)

Usage:
  • (sorted-zipmap-by comparator keys vals)

Type signature:
  • (Function ⨯ [] ⨯ []) → (I ISorted IPersistentMap)

Returns a sorted map with convoluted contents of keys and vals, sorted with comparator.

vec

Available since version 1.0 (view source)

Usage:
  • (vec coll)

Type signature:
  • ([]) → IPersistentVector

Returns a vector with contents of coll.

vec-of

Available since version 1.0 (view source)

Usage:
  • (vec-of t coll)

Type signature:
  • ((U nil Class+ Type Keyword) ⨯ []) → (I IHomogeneous IPersistentVector)

Returns a primitive vector of type t with contents coll.

zipmap

Available since version 1.0 (view source)

Usage:
  • (zipmap keys vals)

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

Returns a map with convoluted contents of keys and vals.

See also: ->map

Empty collections

empty-lst

Available since version 1.0 (alias of dunaj.coll.empty-list/empty-list)

VAR of type EmptyList

An empty list. Same as (). Note that if is often more idiomatic to use nil instead of (any form of) empty list or collection.

empty-map

Available since version 1.0 (alias of dunaj.coll.array-map/empty-array-map)

VAR of type ArrayMap

An empty array map.

empty-que

Available since version 1.0 (alias of dunaj.coll.batched-queue/empty-batched-queue)

VAR of type BatchedQueue

An empty batched queue.

empty-seq

Available since version 1.0 (alias of dunaj.coll.empty-list/empty-list)

VAR of type EmptyList

An empty list. Same as (). Note that if is often more idiomatic to use nil instead of (any form of) empty list or collection.

empty-set

Available since version 1.0 (alias of dunaj.coll.hamt-set/empty-hamt-set)

VAR of type HamtSet

An empty HAMT set.

empty-sorted-map

Available since version 1.0 (alias of dunaj.coll.rbt-sorted-map/empty-rbt-sorted-map)

Usage:
  • (empty-sorted-map)

  • (empty-sorted-map comparator)

Type signatures:
  • () → RbtSortedMap

  • (Function) → RbtSortedMap

Returns an empty RBT map with comparator. Will compare using natural total ordering (see IComparable) if no comparator is given.

empty-sorted-set

Available since version 1.0 (alias of dunaj.coll.rbt-sorted-set/empty-rbt-sorted-set)

Usage:
  • (empty-sorted-set)

  • (empty-sorted-set comparator)

Type signatures:
  • () → RbtSortedSet

  • (Function) → RbtSortedSet

Returns an empty RBT set with comparator. Will compare using natural total ordering (see IComparable) if no comparator is given.

empty-vec

Available since version 1.0 (alias of dunaj.coll.tuple/empty-tuple)

VAR of type Tuple0

An empty tuple.

empty-vec-of

Available since version 1.0 (alias of dunaj.coll.primitive-vector/empty-primitive-vector-of)

Usage:
  • (empty-vec-of t)

Type signature:
  • ((U nil Class+ Type)) → IPersistentVector

Returns an empty primitive vector of given type t, which can be a host class, a type or a keyword. See keyword→class for the list of valid keywords.

Factories

lst-factory

Available since version 1.0 (alias of dunaj.coll.linked-list/linked-list-factory)

not referred automatically

VAR of type ICollectionFactory

A Linked List factory instance. Currently there are no options.

This factory implements ICollectionFactory factory protocol.

New instances of Linked List can be created with collection and ->collection.

map-factory

Available since version 1.0 (alias of dunaj.coll.array-map/array-map-factory)

not referred automatically

VAR of type (U ICollectionFactory IConvolutionFactory)

An Array Map factory instance. Currently there are no options.

This factory implements IConvolutionFactory and ICollectionFactory factory protocols.

New instances of Array Map can be created with collection, ->collection, convolution and ->convolution.

que-factory

Available since version 1.0 (alias of dunaj.coll.batched-queue/batched-queue-factory)

not referred automatically

VAR of type ICollectionFactory

A Batched Queue factory instance. Currently there are no options.

This factory implements ICollectionFactory factory protocol.

New instances of Batched Queue can be created with collection and ->collection.

seq-factory

Available since version 1.0 (view source)

not referred automatically

VAR of type ICollectionFactory

A seq factory instance. Currently there are no options.

This factory implements ICollectionFactory factory protocol.

New instances of seq can be created with collection and ->collection.

set-factory

Available since version 1.0 (alias of dunaj.coll.hamt-set/hamt-set-factory)

not referred automatically

VAR of type ICollectionFactory

A HAMT set factory instance. Currently there are no options.

This factory implements ICollectionFactory factory protocol.

New instances of HAMT set can be created with collection and ->collection.

sorted-map-factory

Available since version 1.0 (alias of dunaj.coll.rbt-sorted-map/rbt-sorted-map-factory)

not referred automatically

VAR of type (U ICollectionFactory IConvolutionFactory)

A RBT sorted map factory instance. Factory has following configuration options:

  • comparator - a comparator used for sorting items. nil represents a natural ordering, implemented with IComparable protocol.

This factory implements ICollectionFactory and IConvolutionFactory factory protocols.

New instances of RBT map can be created with collection, ->collection, convolution and ->convolution.

sorted-set-factory

Available since version 1.0 (alias of dunaj.coll.rbt-sorted-set/rbt-sorted-set-factory)

not referred automatically

VAR of type ICollectionFactory

A RBT sorted set factory instance. Factory has following configuration options:

  • comparator - a comparator used for sorting items. nil represents a natural ordering, implemented with IComparable protocol.

This factory implements ICollectionFactory factory protocols.

New instances of RBT set can be created with collection and ->collection.

vec-factory

Available since version 1.0 (alias of dunaj.coll.tuple/tuple-factory)

not referred automatically

VAR of type ICollectionFactory

A tuple factory instance. Currently there are no options.

This factory implements ICollectionFactory factory protocol.

New instances of tuple can be created with collection and ->collection.

vec-factory-of

Available since version 1.0 (alias of dunaj.coll.primitive-vector/primitive-vector-factory-of)

not referred automatically

Usage:
  • (vec-factory-of t)

Type signature:
  • ((U nil Class+ Type)) → ICollectionFactory

Returns a primitive vector factory for type t, which can be a host class, a type or a keyword. See keyword→class for the list of valid keywords.

New instances of primitive vector can be created with collection and ->collection.