Liking cljdoc? Tell your friends :D

net.cgrand.xforms

Extra transducers for Clojure

Extra transducers for Clojure
raw docstring

avgclj/s


by-keyclj/s

(by-key xform)
(by-key kfn xform)
(by-key kfn vfn xform)
(by-key kfn vfn pair xform)

Returns a transducer which partitions items according to kfn. It applies the transform specified by xform to each partition. Partitions contain the "value part" (as returned by vfn) of each item. The resulting transformed items are wrapped back into a "pair" using the pair function. Default values for kfn, vfn and pair are first, second (or identity if kfn is specified) and vector.

Returns a transducer which partitions items according to kfn.
It applies the transform specified by xform to each partition.
Partitions contain the "value part" (as returned by vfn) of each item.
The resulting transformed items are wrapped back into a "pair" using the pair function.
Default values for kfn, vfn and pair are first, second (or identity if kfn is specified) and vector.
raw docstring

countclj/s

(count rf)
(count xform coll)

Count the number of items. Either used directly as a transducer or invoked with two args as a transducing context.

Count the number of items. Either used directly as a transducer or invoked with two args
as a transducing context.
raw docstring

drop-lastclj/s

(drop-last)
(drop-last n)

ensure-kvrfclj/s

(ensure-kvrf rf)

forclj/smacro

(for [binding %or_ & seq-exprs] body-expr)

Like clojure.core/for with the first expression being replaced by % (or _). Returns a transducer. When the first expression is not % (or _) returns an eduction.

Like clojure.core/for with the first expression being replaced by % (or _). Returns a transducer.
When the first expression is not % (or _) returns an eduction.
raw docstring

intoclj/s

(into to)
(into to from)
(into to xform from)

Like clojure.core/into but with a 1-arg arity returning a transducer which accumulate every input in a collection and outputs only the accumulated collection.

Like clojure.core/into but with a 1-arg arity returning a transducer which accumulate every input in a collection and outputs only the accumulated collection.
raw docstring

into-by-keyclj/s

(into-by-key coll & by-key-args)

A shorthand for the common case (comp (x/by-key ...) (x/into coll)).

A shorthand for the common case (comp (x/by-key ...) (x/into coll)).
raw docstring

iteratorclj

(iterator xform src-iterator)

Iterator transducing context, returns an iterator on the transformed data. Equivalent to (.iterator (eduction xform (iterator-seq src-iterator))) except there's is no buffering on values (as in iterator-seq), This buffering may cause problems when mutable objects are returned by the src-iterator.

Iterator transducing context, returns an iterator on the transformed data.
Equivalent to (.iterator (eduction xform (iterator-seq src-iterator))) except there's is no buffering on values (as in iterator-seq),
This buffering may cause problems when mutable objects are returned by the src-iterator.
raw docstring

keysclj/s

(keys rf)

kvreducible?clj/s

(kvreducible? coll)

kvrfclj/smacro

(kvrf name? & fn-bodies)

KvRfableclj/s≠protocol

Protocol for reducing fns that accept key and val as separate arguments.

Protocol for reducing fns that accept key and val as separate arguments.

some-kvrfclj/s

(some-kvrf f)

Returns a kvrf or nil

Returns a kvrf or nil
raw docstring

lastclj/s


maxclj/s


maximumclj/s

(maximum comparator)
(maximum comparator absolute-minimum)

minclj/s


minimumclj/s

(minimum comparator)
(minimum comparator absolute-maximum)

multiplexclj/s

(multiplex xforms)

Returns a transducer that runs several transducers (sepcified by xforms) in parallel. If xforms is a map, values of the map are transducers and keys are used to tag each transducer output: => (into [] (x/multiplex [(map inc) (map dec)]) (range 3)) [1 -1 2 0 3 1] ; no map, no tag => (into [] (x/multiplex {:up (map inc) :down (map dec)}) (range 3)) [[:up 1] [:down -1] [:up 2] [:down 0] [:up 3] [:down 1]]

Returns a transducer that runs several transducers (sepcified by xforms) in parallel.
If xforms is a map, values of the map are transducers and keys are used to tag each
transducer output:
=> (into [] (x/multiplex [(map inc) (map dec)]) (range 3))
[1 -1 2 0 3 1] ; no map, no tag
=> (into [] (x/multiplex {:up (map inc) :down (map dec)}) (range 3))
[[:up 1] [:down -1] [:up 2] [:down 0] [:up 3] [:down 1]]
raw docstring

partitionclj/s

(partition n)
(partition n step-or-xform)
(partition n step pad-or-xform)
(partition n step pad xform)

Returns a partitioning transducer. Each partition is independently transformed using the xform transducer.

Returns a partitioning transducer. Each partition is independently transformed using the xform transducer.
raw docstring

reduceclj/s

(reduce f)
(reduce f init)

A transducer that reduces a collection to a 1-item collection consisting of only the reduced result. Unlike reduce but like transduce it does call the completing arity (1) of the reducing fn.

A transducer that reduces a collection to a 1-item collection consisting of only the reduced result.
Unlike reduce but like transduce it does call the completing arity (1) of the reducing fn.
raw docstring

reductionsclj/s

(reductions f)
(reductions f init)

Transducer version of reductions. There's a difference in behavior when init is not provided: (f) is used. So x/reductions works like x/reduce or transduce, not like reduce and reductions when no init and 1-item input.

Transducer version of reductions. There's a difference in behavior when init is not provided: (f) is used.
So x/reductions works like x/reduce or transduce, not like reduce and reductions when no init and 1-item input.
raw docstring

sdclj/s


someclj/s

(some xform coll)

Process coll through the specified xform and returns the first local true value.

Process coll through the specified xform and returns the first local true value.
raw docstring

sortclj/s

(sort)
(sort cmp)

sort-byclj/s

(sort-by kfn)
(sort-by kfn cmp)

strclj/s≠

clj
(str xform coll)
cljs
(str rf)
(str xform coll)

When used as a value, it's an aggregating transducer that concatenates input values into a single output value. When used as a function of two args (xform and coll) it's a transducing context that concatenates all values in a string.

When used as a value, it's an aggregating transducer that concatenates input values
into a single output value. 
When used as a function of two args (xform and coll) it's a transducing context that
concatenates all values in a string.
raw docstring

take-lastclj/s

(take-last n)

transjuxtclj/s

(transjuxt xforms-map)
(transjuxt xforms-map coll)

Performs several transductions over coll at once. xforms-map can be a map or a sequential collection. When xforms-map is a map, returns a map with the same keyset as xforms-map. When xforms-map is a sequential collection returns a vector of same length as xforms-map. Returns a transducer when coll is omitted.

Performs several transductions over coll at once. xforms-map can be a map or a sequential collection.
When xforms-map is a map, returns a map with the same keyset as xforms-map.
When xforms-map is a sequential collection returns a vector of same length as xforms-map.
Returns a transducer when coll is omitted.
raw docstring

unreduced->clj/smacro

(unreduced-> x)
(unreduced-> x expr & exprs)

Thread first while threaded value is not reduced. Doesn't unreduce the final value.

Thread first while threaded value is not reduced.
Doesn't unreduce the final value.
raw docstring

valsclj/s

(vals rf)

windowclj/s

(window n f invf)

Returns a transducer which computes an accumulator over the last n items using two functions: f and its inverse invf.

The accumulator is initialized with (f). It is updated to (f (invf acc out) in) where "acc" is the current value, "in" the new item entering the window, "out" the item exiting the window. The value passed to the dowstream reducing function is (f acc) enabling acc to be mutable and 1-arity f to project its state to a value.

If you don't want to see the accumulator until the window is full then you need to use (drop (dec n)) to remove them.

If you don't have an inverse function, consider using partition and reduce: (x/partition 4 (x/reduce rf))

Returns a transducer which computes an accumulator over the last n items
using two functions: f and its inverse invf.

The accumulator is initialized with (f).
It is updated to (f (invf acc out) in) where "acc" is the current value,
"in" the new item entering the window, "out" the item exiting the window.
The value passed to the dowstream reducing function is (f acc) enabling acc to be
mutable and 1-arity f to project its state to a value.

If you don't want to see the accumulator until the window is full then you need to
use (drop (dec n)) to remove them.

If you don't have an inverse function, consider using partition and reduce: 
(x/partition 4 (x/reduce rf))
raw docstring

window-by-timeclj

(window-by-time timef n f)
(window-by-time timef n f invf)

ALPHA Returns a transducer which computes a windowed accumulator over chronologically sorted items.

timef is a function from one item to its scaled timestamp (as a double). The window length is always 1.0 so timef must normalize timestamps. For example if timestamps are in seconds (and under the :ts key), to get a 1-hour window you have to use (fn [x] (/ (:ts x) 3600.0)) as timef.

n is the integral number of steps by which the window slides. With a 1-hour window, 4 means that the window slides every 15 minutes.

f and invf work like in #'window.

ALPHA
Returns a transducer which computes a windowed accumulator over chronologically sorted items.

timef is a function from one item to its scaled timestamp (as a double). The window length is always 1.0
so timef must normalize timestamps. For example if timestamps are in seconds (and under the :ts key),
to get a 1-hour window you have to use (fn [x] (/ (:ts x) 3600.0)) as timef.

n is the integral number of steps by which the window slides. With a 1-hour window, 4 means that the window slides every 15 minutes.

f and invf work like in #'window.
raw docstring

withoutclj/s

(without target)
(without target keys)
(without target xform keys)

The opposite of x/into: dissociate or disjoin from the target.

The opposite of x/into: dissociate or disjoin from the target.
raw docstring

wrapclj/s

(wrap open close)
(wrap open close delim)

Transducer. Adds open as the first item, and close as the last. Optionally inserts delim between each input item.

Transducer. Adds open as the first item, and close as the last. Optionally inserts delim between each input item.
raw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close