(alternates coll)
(alternates threads coll)
Split coll into 'threads' subsequences (defaults to 2), feeding each alternately from the input sequence. Effectively the inverse of interleave:
(alternates 3 (range 9)) ;=> ((0 3 6) (1 4 7) (2 5 8))
Split coll into 'threads' subsequences (defaults to 2), feeding each alternately from the input sequence. Effectively the inverse of interleave: (alternates 3 (range 9)) ;=> ((0 3 6) (1 4 7) (2 5 8))
(assert-length len coll)
Assert, as a side effect, that coll has exactly len elements, and then return coll.
Assert, as a side effect, that coll has exactly len elements, and then return coll.
(cross & seqs)
Computes the cartesian-product of the provided seqs. In other words, compute the set of all possible combinations of ways you can choose one item from each seq.
Computes the cartesian-product of the provided seqs. In other words, compute the set of all possible combinations of ways you can choose one item from each seq.
(extract pred coll)
Extracts the first item that matches pred from coll, returning a vector of that item followed by coll with the item removed.
Extracts the first item that matches pred from coll, returning a vector of that item followed by coll with the item removed.
(find-first pred coll)
Returns the first item of coll where (pred item) returns logical true.
Returns the first item of coll where (pred item) returns logical true.
(find-with pred keys vals)
Returns the val corresponding to the first key where (pred key) returns true.
Returns the val corresponding to the first key where (pred key) returns true.
(flatten-all form)
Takes a nested collection and flattens it into one flat collection. Like clojure.core/flatten, but also works with maps and collections containing nested maps.
Takes a nested collection and flattens it into one flat collection. Like clojure.core/flatten, but also works with maps and collections containing nested maps.
(glue combine glue? coll)
(glue combine init glue? coll)
(glue combine init glue? unglue? coll)
Walk over an input sequence, "gluing" together elements to create batches. Batches may be of any type you like, and are computed as follows:
Walk over an input sequence, "gluing" together elements to create batches. Batches may be of any type you like, and are computed as follows: - Each batch is initialized by combining init (default false) with next-item. - For each additional item in coll, functions glue? and unglue? are consulted to decide whether the next item should be included into the current batch. - If (glue? current-batch next-item) returns truthy, then a prospective updated-batch is computed, as (combine current-batch next-item). If (unglue? updated-batch) returns falsey, then updated-batch is accepted and may be used as the target for further gluing. - If glue? returned falsey, or unglue? returned truthy, then the current batch is inserted into the output sequence, and a new batch is started as (combine init next-item).
(groupings group transform coll)
(groupings group reductor init coll)
Similar to clojure.core/group-by, but allowing you to specify how to add items to each group. For example, if you are grouping by :name, you may want to remove the :name key from each map before adding it to the list. So, you can specify #(dissoc % :name) as your transform.
If you need finer-grained control, you can specify a reduce function for accumulating each group, rather than mapping over the items in it. For example, (groupings even? + 0 coll) finds you the sum of all odd numbers in coll and the sum of all even numbers in coll.
Similar to clojure.core/group-by, but allowing you to specify how to add items to each group. For example, if you are grouping by :name, you may want to remove the :name key from each map before adding it to the list. So, you can specify #(dissoc % :name) as your transform. If you need finer-grained control, you can specify a reduce function for accumulating each group, rather than mapping over the items in it. For example, (groupings even? + 0 coll) finds you the sum of all odd numbers in coll and the sum of all even numbers in coll.
(include? val coll)
Check if val exists in coll.
Check if val exists in coll.
(increasing coll)
(increasing keyfn coll)
(increasing keyfn comp coll)
Throw away any elements from coll which are not in increasing order, according to keyfn and comp (used similarly to the arguments to sort-by).
Throw away any elements from coll which are not in increasing order, according to keyfn and comp (used similarly to the arguments to sort-by).
(increasing* keyfn comp coll)
Scans through a collection, comparing items via (comp (keyfn x) (keyfn y)), and finding those which are in increasing order. Each input item x is output once, as part of a pair, [included? x]. Those items which are part of an increasing sequence will have included? true, while any that go "backwards" from the current max will have included? false.
Scans through a collection, comparing items via (comp (keyfn x) (keyfn y)), and finding those which are in increasing order. Each input item x is output once, as part of a pair, [included? x]. Those items which are part of an increasing sequence will have included? true, while any that go "backwards" from the current max will have included? false.
(indexed coll)
Returns a lazy sequence of pairs of index and item.
Returns a lazy sequence of pairs of index and item.
(insert items n coll)
Inserts a seq of items into coll at position n.
Inserts a seq of items into coll at position n.
(lazy & exprs)
Return a lazy sequence of the passed-in expressions. Each will be evaluated only if necessary.
Return a lazy sequence of the passed-in expressions. Each will be evaluated only if necessary.
(lazy-cross & seqs)
Compute a lazy cartesian-product of the provided seqs. The provided seqs can be lazy or even infinite, and lazy-cross will consume all sequences equally, only consuming more of any sequence when all possible combinations at the current level have been exhausted. This can be thought of intuitively as a breadth-first search of the cartesian product set.
Compute a lazy cartesian-product of the provided seqs. The provided seqs can be lazy or even infinite, and lazy-cross will consume all sequences equally, only consuming more of any sequence when all possible combinations at the current level have been exhausted. This can be thought of intuitively as a breadth-first search of the cartesian product set.
(lazy-loop bindings & body)
Provide a simplified version of lazy-seq to eliminate boilerplate. Arguments are as to the built-in (loop...recur), and (lazy-recur) will be defined for you. However, instead of doing actual tail recursion, lazy-recur trampolines through lazy-seq. In addition to enabling laziness, this means you can call lazy-recur when not in the tail position.
Regular recurs are also supported, if they are in tail position and don't need any laziness.
Provide a simplified version of lazy-seq to eliminate boilerplate. Arguments are as to the built-in (loop...recur), and (lazy-recur) will be defined for you. However, instead of doing actual tail recursion, lazy-recur trampolines through lazy-seq. In addition to enabling laziness, this means you can call lazy-recur when not in the tail position. Regular recurs are also supported, if they are in tail position and don't need any laziness.
(map-nth f nth coll)
(map-nth f start nth coll)
Calls f on every nth element of coll. If start is passed, starts at that element (counting from zero), otherwise starts with zero.
Calls f on every nth element of coll. If start is passed, starts at that element (counting from zero), otherwise starts with zero.
(merge-sorted comparator)
(merge-sorted comparator xs)
(merge-sorted comparator xs ys)
(merge-sorted comparator xs ys & more)
Merge N sorted sequences together, as in the merge phase of a merge-sort.
Comparator should be a two-argument predicate like <
, which returns true if
its first argument belongs before its second element in the merged sequence.
The collections themselves should already be sorted in the order your
comparator would put them; otherwise ordering is undefined.
Merge N sorted sequences together, as in the merge phase of a merge-sort. Comparator should be a two-argument predicate like `<`, which returns true if its first argument belongs before its second element in the merged sequence. The collections themselves should already be sorted in the order your comparator would put them; otherwise ordering is undefined.
(partition-between split? coll)
Partition an input seq into multiple sequences, as with partition-by. Walks the collection two at a time, calling (split? [a b]) for each pair. Any time split? returns truthy, the partition containing a ends, and a new one containing b begins. Note that the split? predicate should not take two arguments, but instead a single argument, a pair.
Like partition-by, a lazy sequence of partitions is returned, but the partitions themselves are eager.
For example, to cause each nil to be folded into the next partition: (partition-between (fn [[a b]] (not (nil? a))) '[1 nil nil 2 nil 3]) => ([1] [nil nil 2] [nil 3])
Partition an input seq into multiple sequences, as with partition-by. Walks the collection two at a time, calling (split? [a b]) for each pair. Any time split? returns truthy, the partition containing a ends, and a new one containing b begins. Note that the split? predicate should not take two arguments, but instead a single argument, a pair. Like partition-by, a lazy sequence of partitions is returned, but the partitions themselves are eager. For example, to cause each nil to be folded into the next partition: (partition-between (fn [[a b]] (not (nil? a))) '[1 nil nil 2 nil 3]) => ([1] [nil nil 2] [nil 3])
(prefix-of? coll prefix)
Given prefix is N elements long, are the first N elements of coll equal to prefix?
Given prefix is N elements long, are the first N elements of coll equal to prefix?
(remove-prefix prefix coll)
Remove prefix from coll, returning the remaining suffix. Returns nil if prefix does not match coll.
Remove prefix from coll, returning the remaining suffix. Returns nil if prefix does not match coll.
(separate pred coll)
Split coll into two sequences, one that matches pred and one that doesn't. Unlike the version in clojure.contrib.seq-utils, pred is only called once per item.
Split coll into two sequences, one that matches pred and one that doesn't. Unlike the version in clojure.contrib.seq-utils, pred is only called once per item.
(seque* s)
(seque* n-or-q s)
A version of clojure.core/seque that fixes a memory/thread-handle leak.
A version of clojure.core/seque that fixes a memory/thread-handle leak.
(sequeue s)
(sequeue n-or-q s)
A version of seque from clojure.core that uses a future instead of an agent. The agent version was causing problems because you can't depend on an agent from within another agent's action, which means you can't use seque inside an agent.
This version is probably less performant, because it keeps a thread running until the sequence is entirely consumed, and it attempts to refill the queue as soon as there is space, rather than when the queue is emptied.
More importantly, though, this version may be DANGEROUS if you are not careful: if you do not consume the entire output sequence, the future-thread will remain active indefinitely, blocking on the queue and holding the lazy sequence open, ineligible for garbage collection.
A version of seque from clojure.core that uses a future instead of an agent. The agent version was causing problems because you can't depend on an agent from within another agent's action, which means you can't use seque inside an agent. This version is probably less performant, because it keeps a thread running until the sequence is entirely consumed, and it attempts to refill the queue as soon as there is space, rather than when the queue is emptied. More importantly, though, this version may be *DANGEROUS* if you are not careful: if you do not consume the entire output sequence, the future-thread will remain active indefinitely, blocking on the queue and holding the lazy sequence open, ineligible for garbage collection.
(single? coll)
Does coll have only one element?
Does coll have only one element?
(slice n coll)
Divide coll into n approximately equal slices.
Divide coll into n approximately equal slices.
(take-shuffled n coll)
Lazily take (at most) n elements at random from coll, without replacement. For n=1, this is equivalent to rand-nth; for n>=(count coll) it is equivalent to shuffle.
Clarification of "without replacement": each index in the original collection is chosen at most once. Thus if the original collection contains no duplicates, neither will the result of this function. But if the original collection contains duplicates, this function may include them in its output: it does not do any uniqueness checking aside from being careful not to use the same index twice.
Lazily take (at most) n elements at random from coll, without replacement. For n=1, this is equivalent to rand-nth; for n>=(count coll) it is equivalent to shuffle. Clarification of "without replacement": each index in the original collection is chosen at most once. Thus if the original collection contains no duplicates, neither will the result of this function. But if the original collection contains duplicates, this function may include them in its output: it does not do any uniqueness checking aside from being careful not to use the same index twice.
(take-until pred coll)
Take from coll up to and including the first item that satisfies pred.
Take from coll up to and including the first item that satisfies pred.
(unchunk s)
Create a one-at-a-time sequence out of a chunked sequence.
Create a one-at-a-time sequence out of a chunked sequence.
(unfold next seed)
Traditionally unfold is the 'opposite of reduce': it turns a single seed value into a (possibly infinite) lazy sequence of output values.
Next is a function that operates on a seed: it should return a pair, [value new-seed]; the value half of the pair is inserted into the resulting list, while the new seed is used to continue unfolding. Notably, the value is never passed as an argument to next. If nil is returned instead of a pair, the resulting sequence will terminate.
(defn fibs [] (unfold (fn [[a b]] [a [b (+ a b)]]) [0 1]))
Traditionally unfold is the 'opposite of reduce': it turns a single seed value into a (possibly infinite) lazy sequence of output values. Next is a function that operates on a seed: it should return a pair, [value new-seed]; the value half of the pair is inserted into the resulting list, while the new seed is used to continue unfolding. Notably, the value is never passed as an argument to next. If nil is returned instead of a pair, the resulting sequence will terminate. (defn fibs [] (unfold (fn [[a b]] [a [b (+ a b)]]) [0 1]))
(update-first coll pred f)
(update-first coll pred f & args)
Returns a lazy-seq that is a version of coll with the first item matching pred updated by calling f on it with the supplied args.
Returns a lazy-seq that is a version of coll with the first item matching pred updated by calling f on it with the supplied args.
(zip & colls)
Returns a lazy sequence of vectors of corresponding items from each collection. If one collection is longer than the others, the missing items will be filled in with nils.
Returns a lazy sequence of vectors of corresponding items from each collection. If one collection is longer than the others, the missing items will be filled in with nils.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close