Creates an empty stream with no items.
Type of the items of the produced stream.
A stream with no items.
Creates an stream for iterating over an object's key-value-pairs. Only the object's own property are included.
fromObject({foo:2, bar: 3})
// => Stream[ {key: "foo", value: 2}, {key: "bar", value: 3} ]
Type of the object's values.
The object with the key-value-pairs to be iterated.
A stream with the object's key-value-pairs.
Creates a stream for iterating over an object's keys. Only the object's own property are included.
fromObjectKeys({foo:2, bar: 3, 42: 9})
// => Stream["foo", "bar", "42"]
The object with the keys to be iterated.
A stream with the object's keys.
Creates a stream for iterating over an object's values. Only the object's own property are included.
fromObjectValues({foo:2, bar: 3})
// => Stream[2,3]
Type of the object's values.
The object with the values to be iterated.
A stream with the object's values.
Creates a stream with the items provided by the given generator.
generate(index => index) // => Stream[0,1,2,3,4,...]
generate(index => index, 0) // => Stream[]
generate(index => index) // => Stream[0,1,2,3,4,...]
generate(index => index, Infinity) // => Stream[0,1,2,3,4,...]
generate(index => index, -Infinity) // => Stream[]
generate(index => index, NaN) // => Stream[]
Type of the items of the produced stream.
Generator for generating the items of the iterable. It is passed the current index as its argument.
How many items to generate, Infinity
for an unlimited amount.
Stream for iterating the given amount of times over the items supplied by the supplier.
Creates a stream starting with the initial seed.
iterate(42, x => (0x19660D * x + 0x3C6EF35F) % 0x100000000)
// Random number generator, linear congruential generator from "Numerical Recipes".
iterate(2, x => 2*x, 3) // => Stream[2,4,8]
iterate(2, x => 2*x, 0) // => Stream[]
iterate(2, x => 2*x, Infinity) // => Stream[2,4,8,16,...]
iterate(2, x => 2*x, -Infinity) // => Stream[]
iterate(2, x => 2*x, NaN) // => Stream[]
Type of the items of the produced stream.
Initial item.
Function that takes the current item and produces the next item in the sequence.
How many times to iterate, Infinity
for an unlimited amount.
Stream for iterating over the provided items the given amount of times.
Creates a stream of random numbers. The generated numbers are
in the interval [0,1]
. When the amount of numbers to generate
is not specified, an unlimited amount of numbers are generated.
Use methods such as {@link IStream#limit} to limit the stream.
Please note that the generated numbers are not cryptographically secure random numbers and must not be used in any context dealing with security.
random(3).toArray() // => [3 random numbers]
random(-1).toArray() // => []
random(Infinity).limit(5) // => [5 random numbers]
random(10).first() // => 1 random number
How many random numbers to generate. Defaults to Infinity
.
A stream with the specified amount of random numbers.
Creates an stream with the given item occuring the given number of times.
repeat(0, 9)
// => Stream[0,0,0,0,0,0,0,0,0]
repeat(0, 0) // => Stream[]
repeat(0, -Infinity) // => Stream[]
repeat(0, Infinity) // => Stream[0,0,0,...]
repeat(0, NaN) // => Stream[]
Type of the items of the produced stream.
Item to repeat.
How many times to repeat, Infinity
for an unlimited amount.
Stream contains the given item the given number of times.
Creates a stream with numbers starting at the given value and separated from each other by the given step.
times(3) // => Stream(0,1,2)
times(3, 4) // => Stream(4, 5, 6)
times(3, 4, 8) // => Stream(4, 12, 20)
times(-3) // => Stream()
times(3, -4) // => Stream(-4, -3, -2)
times(3, 4, -2) // => Stream(4, 2, 0)
times(3, -4, -2) // => Stream(-4, -6, -8)
times(Infinity) // => Stream(0, 1, 2, 3, ...)
times(-Infinity) // => Stream()
times(Infinity, 5) // => Stream(5, 6, 7, 8, ...)
times(Infinity, 5, 2) // => Stream(5, 7, 9, 11, ...)
times(3, Infinity) // => Stream(Infinity, Infinity, Infinity)
times(4, 0, Infinity) // => Stream(0, Infinity, Infinity, Infinity)
times(4, Infinity, Infinity) // => Stream(Infinity, Infinity, Infinity, Infinity)
times(4, -Infinity, Infinity) // => Stream(-Infinity, NaN, NaN, NaN)
times(Infinity, 2, Infinity) // => Stream(2, Infinity, Infinity, Infinity, ...)
times(Infinity, Infinity, 2) // => Stream(Infinity, Infinity, Infinity, Infinity, ...)
times(Infinity, -Infinity, 2) // => Stream(-Infinity, -Infinity, -Infinity, -Infinity, ...)
times(Infinity, Infinity, Infinity) // => Stream(Infinity, Infinity, Infinity, Infinity, ...)
times(NaN) // => Stream()
times(5, NaN) // => Stream(NaN, NaN, NaN, NaN, NaN)
times(5, 1, NaN) // => Stream(1, NaN, NaN, NaN, NaN)
times(5, Infinity, NaN) // => Stream(Infinity, NaN, NaN, NaN, NaN)
times(5, -Infinity, NaN) // => Stream(-Infinity, NaN, NaN, NaN, NaN)
times(5, NaN, 2) // => Stream(NaN, NaN, NaN, NaN, NaN)
times(5, NaN, NaN) // => Stream(NaN, NaN, NaN, NaN, NaN)
times(NaN, NaN, NaN) // => Stream()
Number of items to produce. Must not be negative.
Initial number, defaults to 0.
How far apart the individual items are, defaults to 1.
Stream with the configured numbers.
Creates a stream from the given iterable. The iterable is consumed as part of stream operations. If it is not a repeatable iterable and multiple iterations over it are required, use {@link IStream#fork}. The iterable is queried only on-demand, thus allowing for generators that produce an unlimited number of items.
const stream1 = factory.stream("foo");
// => Stream["f", "o", "o"]
const stream2 = factory.stream("[1,2,3]");
// => Stream[1, 2, 3]
const stream3 = factory.stream(new Set([1,2,3]).values());
// => Stream[1, 2, 3]
function * generator() {
let i = 0;
while (true) yield ++i;
}
const stream4 = factory.stream(generator());
// => Stream[1, 2, 3, 4, 5, 6, ...]
Type of the items of the produced stream.
A stream over the iterables' values.
Creates an stream with numbers starting at the given value and ending at the given value.
times(3) // => Stream[0, 1, 2]
times(3, 4) // => Stream[4, 5, 6]
times(3, 4, 8) // => Stream[4, 6, 8]
times(1, 10, 12) // => Stream[10]
times(0) // => Stream[]
times(3, 0, -2) // => Stream[0, -1, -2]
times(-3) // => Stream[]
times(5, 0, Infinity) // => Stream(0, NaN, NaN, NaN, Infinity)
times(5, Infinity, 0) // => Stream(Infinity, NaN, NaN, NaN, 0)
times(Infinity) // => Stream(0, 0, 0, 0, ...)
times(Infinity, 2, 3) // => Stream(2, 2, 2, 2, ...)
times(NaN) // => Stream()
times(5, NaN) // => Stream(NaN, NaN, NaN, NaN, NaN)
times(5, 2, NaN) // => Stream(2, NaN, NaN, NaN, NaN)
times(5, NaN, 7) // => Stream(NaN, NaN, NaN, NaN, 7)
times(NaN, 0, 5) // => Stream()
times(NaN, NaN, NaN) // => Stream()
Number of items to produce. Must not be negative.
Initial number, defaults to 0.
Last number, defaults to start+amount-1
. May be smaller than end, in which case numbers of decreasing value are generated.
Stream with the configured numbers.
Generated using TypeDoc
Factory for creating streams. One of the most common methods is
IStreamFactory#stream(iterable)
, which wraps an iterable such asarray
orset
in an object-oriented stream.