### Useful functions on sequential datastructures
(assoc-nth-in m [k & ks] v)
Like assoc-in but also works on lists.
Like assoc-in but also works on lists.
(get-nth-in init ks)
Like get-in but also works on lists.
Like get-in but also works on lists.
(max-by f x)
(max-by f x y)
(max-by f x y & more)
Returns the greatest of the elements by pred.
Returns the greatest of the elements by pred.
(min-by f x)
(min-by f x y)
(min-by f x y & more)
Returns the least of the elements by pred.
Returns the least of the elements by pred.
(order array constraints)
Order a sequence with a collection of constraints of the form:
Can specify constraints on :all
elements.
Raises an exception if constraints are contradictory.
Example:
(order [1 2 3] {2 1 3 :all})
(order [1 2 3] [[2 1] [3 :all]])
(order [1 2 3] [[2 :before 1] [:all :after 3]])
(order [1 2 3] [[2 :> 1] [:all :< 3]])
;; (3 2 1)
Order a sequence with a collection of constraints of the form: - [a b] - [a :before b] - [a :> b] - [b :after a] - [b :< a] Can specify constraints on `:all` elements. Raises an exception if constraints are contradictory. Example: ```clojure (order [1 2 3] {2 1 3 :all}) (order [1 2 3] [[2 1] [3 :all]]) (order [1 2 3] [[2 :before 1] [:all :after 3]]) (order [1 2 3] [[2 :> 1] [:all :< 3]]) ;; (3 2 1) ```
(separate pred coll)
Returns a vector of [(filter pred coll) (remove pred coll)]
.
(let [coll [1 1 0 1 0 0 1 1 0]]
(separate zero? coll)
=> [(1 1 1 1 1) (0 0 0 0)])
Returns a vector of `[(filter pred coll) (remove pred coll)]`. ```clojure (let [coll [1 1 0 1 0 0 1 1 0]] (separate zero? coll) => [(1 1 1 1 1) (0 0 0 0)]) ```
(slice delimiter?
coll
&
{:keys [include-delimiter include-empty]
:or {include-delimiter false include-empty false}})
Slice a seq using a delimiter predicate. There are two options:
- :include-delimiter false | :left | :right
whether to include the delimiter and where
- :include-empty true | false
whether to create empty seqs between
successive delimiters
(let [coll [1 1 0 1 0 0 1 1]]
;; the default
(slice zero? coll) ;; by default, :include-delimiter false,
:include-empty false
=> ((1 1) (1) (1 1))
(slice zero? coll :include-empty true)
=> ((1 1) (1) () (1 1))
(slice zero? coll :include-delimiter :left)
=> ((1 1) (0 1) (0 1 1))
(slice zero? coll :include-delimiter :right)
=> ((1 1 0) (1 0) (1 1))
(slice zero? coll :include-delimiter :right :include-empty true)
=> ((1 1 0) (1 0) (0) (1 1))
)
Slice a seq using a delimiter predicate. There are two options: ``` - :include-delimiter false | :left | :right whether to include the delimiter and where - :include-empty true | false whether to create empty seqs between successive delimiters ``` ```clojure (let [coll [1 1 0 1 0 0 1 1]] ;; the default (slice zero? coll) ;; by default, :include-delimiter false, :include-empty false => ((1 1) (1) (1 1)) (slice zero? coll :include-empty true) => ((1 1) (1) () (1 1)) (slice zero? coll :include-delimiter :left) => ((1 1) (0 1) (0 1 1)) (slice zero? coll :include-delimiter :right) => ((1 1 0) (1 0) (1 1)) (slice zero? coll :include-delimiter :right :include-empty true) => ((1 1 0) (1 0) (0) (1 1)) ) ```
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close