std.lib.collection

assoc-new

added in 3.0

(assoc-new m k v)(assoc-new m k v & more)

only assoc if the value in the original map is nil

(assoc-new {:a 1} :b 2) => {:a 1 :b 2}

(assoc-new {:a 1} :a 2 :b 2) => {:a 1 :b 2}

cons?

added in 3.0

(cons? x)

checks if object is instance of clojure.lang.Cons

(cons? (cons 1 1 2 3)) => true

deduped?

added in 3.0

(deduped? coll)

checks if elements in the collection are unique

(deduped? 1 2 3 4) => true

(deduped? 1 2 1 4) => false

diff

added in 3.0

(diff m1 m2)(diff m1 m2 reversible)

Finds the difference between two maps

diff:changed

added in 3.0

(diff:changed new old)

Outputs what has changed between the two maps

(diff:changed {:a {:b {:c 3 :d 4}}} {:a {:b {:c 3}}}) => {:a {:b {:d 4}}}

diff:changes

added in 3.0

(diff:changes m1 m2)(diff:changes m1 m2 arr equal-fn)

Finds changes in nested maps, does not consider new elements

diff:new

added in 3.0

(diff:new m1 m2)(diff:new m1 m2 arr)

Finds new elements in nested maps, does not consider changes

diff:patch

added in 3.0

(diff:patch m diff)

patch from old to new

diff:unpatch

added in 3.0

(diff:unpatch m diff)

unpatch from new to old

dissoc-nested

added in 3.0

(dissoc-nested m [k & ks])

dissocs recursively into a map removing empty entries

(dissoc-nested {:a {:b {:c 1}}} :a :b :c) => {}

element-at

added in 3.0

(element-at pred coll)

finds the element within an array

(element-at keyword? 1 2 :hello 4) => :hello

empty-record

added in 3.0

(empty-record v)

creates an empty record from an existing one

(defrecord Database host port)

(empty-record (Database. “localhost” 8080)) => (just {:host nil :port nil})

filter-keys

added in 3.0

(filter-keys pred m)

filters map based upon map keys

(filter-keys even? {0 :a 1 :b 2 :c}) => {0 :a, 2 :c}

filter-vals

added in 3.0

(filter-vals pred m)

filters map based upon map values

(filter-vals even? {:a 1 :b 2 :c 3}) => {:b 2}

find-templates

added in 3.0

(find-templates m)(find-templates m path saved)

finds the template with associated path

flatten-nested

added in 3.0

(flatten-nested x)

flattens all elements the collection

(flatten-nested 1 2 #{3 {4 5}}) => 1 2 3 4 5

form?

added in 3.0

(form? form)

checks if object is a lisp form

hash-map?

added in 3.0

(hash-map? x)

Returns true if x implements clojure.lang.APersistentMap.

(hash-map? {}) => true (hash-map? []) => false

index-at

added in 3.0

(index-at pred coll)

finds the index of the first matching element in an array

(index-at even? 1 2 3 4) => 1

(index-at keyword? 1 2 :hello 4) => 2

insert-at

added in 3.0

(insert-at coll i new)(insert-at coll i new & more)

insert one or more elements at the given index

(insert-at :a :b 1 :b :c) => :a :b :c :b

keep-vals

added in 3.0

(keep-vals f m)(keep-vals f pred m)

filters map based upon map values

(keep-vals even? {:a 1 :b 2 :c 3}) => {:b true}

lazy-seq?

added in 3.0

(lazy-seq? x)

Returns true if x implements clojure.lang.LazySeq.

(lazy-seq? (map inc 1 2 3)) => true (lazy-seq? ()) => false

map-entries

added in 3.0

(map-entries f m)

manipulates a map given the function

(map-entries (fn k v (keyword (str v)) (name k)) {:a 1 :b 2 :c 3}) => {:1 “a”, :2 “b”, :3 “c”}

map-juxt

added in 3.0

(map-juxt [kf vf] arr)

creates a map from sequence with key and val functions

(map-juxt str inc 1 2 3 4 5) => {“1” 2, “2” 3, “3” 4, “4” 5, “5” 6}

map-keys

added in 3.0

(map-keys f m)

changes the keys of a map

(map-keys inc {0 :a 1 :b 2 :c}) => {1 :a, 2 :b, 3 :c}

map-vals

added in 3.0

(map-vals f m)

changes the values of a map

(map-vals inc {:a 1 :b 2 :c 3}) => {:a 2, :b 3, :c 4}

merge-meta

(merge-meta obj metadata)

merge-nested

added in 3.0

(merge-nested & maps)

Merges nested values from left to right.

(merge-nested {:a {:b {:c 3}}} {:a {:b 3}}) => {:a {:b 3}}

(merge-nested {:a {:b {:c 1 :d 2}}} {:a {:b {:c 3}}}) => {:a {:b {:c 3 :d 2}}}

merge-nested-new

added in 3.0

(merge-nested-new & maps)

Merges nested values from left to right, provided the merged value does not exist

(merge-nested-new {:a {:b 2}} {:a {:c 2}}) => {:a {:b 2 :c 2}}

(merge-nested-new {:b {:c :old}} {:b {:c :new}}) => {:b {:c :old}}

pmap-entries

added in 3.0

(pmap-entries f m)

uses pmap across the entries

pmap-vals

added in 3.0

(pmap-vals f m)

uses pmap across the map values

qualified-keys

added in 3.0

(qualified-keys m)(qualified-keys m ns)

takes only the namespaced keys of a map

(qualified-keys {:a 1 :ns/b 1}) => #:ns{:b 1}

(qualified-keys {:a 1 :ns.1/b 1 :ns.2/c 1} :ns.1) => #:ns.1{:b 1}

qualify-keys

added in 3.0

(qualify-keys m ns)

lifts all unqualified keys

(qualify-keys {:a 1} :ns.1) => #:ns.1{:a 1}

(qualify-keys {:a 1 :ns.2/c 1} :ns.1) => {:ns.1/a 1, :ns.2/c 1}

queue

added in 3.0

(queue)(queue x)(queue x & xs)

returns a clojure.lang.PersistentQueue object.

(pop a) => 2 3 4

re-create

remove-at

added in 3.0

(remove-at coll i)(remove-at coll i n)

removes element at the specified index

(remove-at :a :b :c :d 2) => :a :b :d

rename-keys

added in 4.0

(rename-keys m trs)

rename keys in map

(rename-keys {:a 1} {:a :b}) => {:b 1}

reshape

added in 3.0

(reshape m rels)

moves values around in a map according to a table

(reshape {:a 1 :b 2} {:c :d :a}) => {:b 2, :c {:d 1}}

seqify

added in 3.0

(seqify x)

if not a sequence, then make one

(seqify 1) => 1

(seqify 1) => 1

split-by

added in 4.0

(split-by pred coll)

splits a sequences using a predicate

transform

added in 3.0

(transform schema [from to] data)

creates a transformation function

transform-fn

added in 3.0

(transform-fn schema [from to])

creates a transformation function ((transform-fn {:keystore {:hash “{{hash}}” :salt “{{salt}}” :email “{{email}}”}

            :db       {:login {:user {:hash "{{hash}}"
                                      :salt "{{salt}}"}
                               :value "{{email}}"}}}
           [:keystore :db]) ^:hidden

{:type :email, :hash “1234” :salt “ABCD” :email “[email protected]”}) => {:type :email :login {:user {:hash “1234”, :salt “ABCD”}, :value “[email protected]”}}

transform-fn*

transpose

added in 3.0

(transpose m)

sets the vals and keys and vice-versa

(transpose {:a 1 :b 2 :c 3}) => {1 :a, 2 :b, 3 :c}

tree-flatten

added in 3.0

(tree-flatten m)(tree-flatten m sep)(tree-flatten m sep path)

flattens the entire map tree

(->> (tree-flatten {“a” {“b” {“c” 3 “d” 4} “e” {“f” 5 “g” 6}} “h” {“i” {}}}) (map-keys h/strn)) => {“a/b/c” 3, “a/b/d” 4, “a/e/f” 5, “a/e/g” 6}

tree-nestify

added in 3.0

(tree-nestify m)(tree-nestify m sep)(tree-nestify m sep f)

nests keys in the map

(tree-nestify {:a/b 2 :a/c 3}) => {:a {:b 2 :c 3}}

(tree-nestify {:a/b {:e/f 1} :a/c {:g/h 1}}) => {:a {:b {:e/f 1} :c {:g/h 1}}}

tree-nestify:all

added in 3.0

(tree-nestify:all m)(tree-nestify:all m sep)

nests keys in the map and all submaps

(tree-nestify:all {:a/b 2 :a/c 3}) => {:a {:b 2 :c 3}}

(tree-nestify:all {:a/b {:e/f 1} :a/c {:g/h 1}}) => {:a {:b {:e {:f 1}} :c {:g {:h 1}}}}

unfold

added in 3.0

(unfold f coll)

unfolds using a generated function

(unfold (fn i :as seed (if i (if-not (neg? i) [(* i 2) (dec i)]))) 10) => 20 18 16 14 12 10 8 6 4 2 0

unlazy

added in 3.0

(unlazy x)

works on both lazy seqs and objects

unqualified-keys

added in 3.0

(unqualified-keys m)

takes only the namespaced keys of a map

(unqualified-keys {:a 1 :ns/b 1}) => {:a 1}

unqualify-keys

added in 3.0

(unqualify-keys m)(unqualify-keys m ns)

unqualifies keys in the map

(unqualify-keys {:a 1 :ns.1/b 1 :ns.2/c 1}) => {:a 1, :b 1, :c 1}

(unqualify-keys {:a 1 :ns.1/b 1 :ns.2/c 1} :ns.1) => {:a 1, :b 1, :ns.2/c 1}

unseqify

added in 3.0

(unseqify x)

if a sequence, takes first element

(unseqify 1) => 1

(unseqify 1) => 1