Clojure/ClojureScript utilities for collections
[com.kineticfire/collections "1.0.0"]
com.kineticfire/collections {:mvn/version "1.0.0"}
implementation("com.kineticfire:collections:1.0.0")
<dependency>
<groupId>com.kineticfire</groupId>
<artifactId>collections</artifactId>
<version>1.0.0</version>
</dependency>
(not-empty? col)
Returns boolean 'true' if the collection col
is not empty and 'false' otherwise. Suitable for vectors, lists,
maps, and strings. Uses an implementation with the recommended idiom 'seq col' but is more readable, regardless of
experience.
(not-empty? [1])
;;=> true
(not-empty? [])
;;=> false
(not-empty? {:a 1})
;;=> true
(not-empty? {})
;;=> false
(not-empty? "hello")
;;=> true
(not-empty? "")
;;=> false
(contains-value? col val)
Returns boolean 'true' if the value val
is contained in the collection col
and 'false' otherwise. For a map,
searches values at the current level only.
(contains-value? [1 2 3] 2)
;;=> true
(contains-value? [1 2 3] 4)
;;=> false
(contains-value? {:a 1} 1)
;;=> true
(contains-value? {:a 1} 2)
;;=> false
;; for a map, searches current level of keys only
(contains-value? {:a {:b 2}} 2)
;;=> false
(find-duplicates col)
Returns a vector of duplicates found in the collection 'col'. If no duplicates, then returns an empty vector. For a map, searches values at the current level only.
(find-duplicates [1 2 2 3 3])
;;=> [2 3]
(find-duplicates [1 2 3])
;;=> []
(find-duplicates {:a 1 :b 2 :c 2 :d 3 :e 3})
;;=> [2 3]
(find-duplicates {:a 1 :b 2 :c 3})
;;=> []
;; for a map, searches current level of keys only
(find-duplicates {:z {:a 1 :b 2 :c 2 :d 3 :e 3}})
;;=> []
(duplicates? col)
Returns boolean 'true' if the collection col
contains at least one duplicate and 'false' otherwise. For a map,
searches values at the current level only. Similar to 'clojure.core/distinct?', but its values are taken separately (e.g., not in a collection) while this
function operates on collections.
(duplicates? [1 2 2 3 3])
;;=> true
(duplicates? [1 2 3])
;;=> false
(duplicates? {:a 1 :b 2 :c 2 :d 3 :e 3})
;;=> true
(duplicates? {:a 1 :b 2 :c 3})
;;=> false
;; for a map, searches current level of keys only
(duplicates? {:z {:a 1 :b 2 :c 2 :d 3 :e 3}})
;;=> false
(assoc-in m ks v) (assoc-in m ks-v-seq)
Associates a value in a nested associative structure as with 'clojure.core/assoc-in', but also accepts a sequence of key sequence / value pairs to associate multiple values in one call. If any levels do not exist, hash-maps will be created.
(def data {:a {:b 1}})
;; calling (assoc-in m ks v) calls clojure.core/assoc-in to associate one new entry
(assoc-in data [:a :c] 2)
;;=> {:a {:b 1 :c 2}}
;; calling (assoc-in m ks-v-seq) associates one or more new entries
(assoc-in data [ [[:a :c] 2] [[:a :d :e] 3] ])
;;=> {:a {:b 1 :c 2 :d {:e 3}}}
(dissoc-in m ks)
Disassociates a value in a nested associative structure m
, where ks
is either a sequence of keys or a sequence
of key sequences.
(def data {:a {:b 1 :c 2}})
;; remove a single entry
(dissoc-in data [:a :b])
;;=> {:a {:c 2}}
;; remove multiple entries
(dissoc-in data [[:a :b] [:a :c]])
;;=> {:a {}}
(symmetric-difference set1 set2)
Returns a set that is the symmetric difference between the first set set1
and second set set2
. That is, the
returned set contains all the values that are present in one set but not the other.
(symmetric-difference #{} #{})
;;=> #{}
(symmetric-difference #{1} #{})
;;=> #{1}
(symmetric-difference #{} #{1})
;;=> #{1}
(symmetric-difference #{1 2 3} #{ 1 2 4})
;;=> #{3 4}
The clojure-collections project is released under Apache License 2.0
Can you improve this documentation? These fine people already did:
kineticfire-labs & Kris HallEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close