API for stream-utils
- ()
by Konrad Hinsen
clojure-contrib is now deprecated
clojure-contrib is no longer being developed or maintained.
Rather than a single, monolithic, contributions library, Clojure now has
a set of separate libraries for each unit of functionality. The libraries
are in the Clojure GitHub organization at
https://github.com/clojure.
API documentation of the libraries can be found at
https://clojure.github.io.
If you're looking for a specific function or namespace from the old
clojure-contrib, see
"Where Did Clojure.Contrib Go".
Full namespace name:
clojure.contrib.stream-utils
Overview
Functions for setting up computational pipelines via data streams.
NOTE: This library is experimental. It may change significantly
with future release.
This library defines:
- an abstract stream type, whose interface consists of the
multimethod stream-next
- a macro for implementing streams
- implementations of stream for
1) Clojure sequences, and vectors
2) nil, representing an empty stream
- tools for writing stream transformers, including the
monad stream-m
- various utility functions for working with streams
Streams are building blocks in the construction of computational
pipelines. A stream is represented by its current state plus
a function that takes a stream state and obtains the next item
in the stream as well as the new stream state. The state is
implemented as a Java class or a Clojure type (as defined by the
function clojure.core/type), and the function is provided as an
implementation of the multimethod stream-next for this class or type.
While setting up pipelines using this mechanism is somewhat more
cumbersome than using Clojure's lazy seq mechanisms, there are a
few advantages:
- The state of a stream can be stored in any Clojure data structure,
and the stream can be re-generated from it any number of times.
Any number of states can be stored this way.
- The elements of the stream are never cached, so keeping a reference
to a stream state does not incur an uncontrollable memory penalty.
Note that the stream mechanism is thread-safe as long as the
concrete stream implementations do not use any mutable state.
Stream transformers take any number of input streams and produce one
output stream. They are typically written using the stream-m
monad. In the definition of a stream transformer, (pick s) returns
the next value of stream argument s, whereas pick-all returns the
next value of all stream arguments in the form of a vector.
Public Variables and Functions
defst
macro
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (defst name args streams & body)
Define the stream transformer name by body.
The non-stream arguments args and the stream arguments streams
are given separately, with args being possibly empty.
Source
defstream
macro
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (defstream type-tag args & body)
Define object of the given type as a stream whose implementation
of stream-next is defined by args and body. This macro adds
a type-specific method for stream-next and derives type
from stream-type.
Source
pick
function
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (pick n)
Return the next value of stream argument n inside a stream
transformer. When used inside of defst, the name of the stream
argument can be used instead of its index n.
Source
pick-all
function
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (pick-all streams)
Return a vector containing the next value of each stream argument
inside a stream transformer.
Source
stream-drop
function
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (stream-drop n stream)
Return a stream containing all but the first n elements of stream.
Source
stream-flatten
function
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (stream-flatten s)
Converts a stream of sequences into a stream of the elements of the
sequences. Flattening is not recursive, only one level of nesting
will be removed.
Source
stream-m
var
This library, clojure-contrib, is deprecated. See here for more information.
Monad describing stream computations. The monadic values can be
of any type handled by stream-next.
Source
stream-seq
function
This library, clojure-contrib, is deprecated. See here for more information.
Usage: (stream-seq s)
Return a lazy seq on the stream. Also accessible via
clojure.contrib.seq/seq-on and
clojure.contrib.generic.collection/seq for streams.
Source
stream-type
var
This library, clojure-contrib, is deprecated. See here for more information.
The root type for the stream hierarchy. For each stream type,
add a derivation from this type.
Source