Type of the items to be collected.
An optional converter for turning items into numbers. Default to item => Number(item)
.
A collector that converts each item into a number and computes their (arithmetic) mean.
Computes the geometric average of all the collected items, ie.
(x_1 * x_2 * ... * x_n)/n
, where n
is the number of
items and the x_i
are the individual items. Returns NaN
when there are no items.
factory.stream([]).collect(Collectors.averageGeometrically());
// => NaN
factory.stream([2, 4, 8]).collect(Collectors.averageGeometrically());
// => 4
const letterAverage = Collectors.averageGeometrically(x => x.length);
factory.stream(["fish", "is", "allergic"]).collect(letterAverage);
// => 4
Type of the items to be collected.
An optional converter for turning items into numbers. Default to item => Number(item)
.
A collector that converts each item into a number and computes their geometric mean.
Computes the harmonic average of all the collected items, ie.
n/(1/x_1 + 1/x_2 + ... + 1/x_n)
, where n
is the number of items and the
x_i
are the individual items. Returns NaN
when there are no
items.
factory.stream([]).collect(Collectors.averageHarmonically());
// => NaN
factory.stream([2, 4, 6, 8]).collect(Collectors.averageHarmonically());
// => 3.84
const letterAverage = Collectors.averageHarmonically(x => x.length);
factory.stream(["is", "fish", "likely", "allergic"]).collect(letterAverage);
// => 3.84
Type of the items to be collected.
An optional converter for turning items into numbers. Default to item => Number(item)
.
A collector that converts each item into a number and computes their harmonic mean.
Counts the number of items.
factory.stream([4,1,0,4]).collect(Collectors.count())
// => 4
A collector that counts the number of items.
Splits the items into several groups, according to the given classifier.
factory.stream(["a", "foo", "is", "some", "buzz"]).collect(Collectors.group(x => x.length))
// => Map [ 1 => ["a"], 2 => ["is"], 3 => "is", 4 => ["some", "buzz"] ]
Type of the items to be collected.
Returns the group for each item.
A map with the groups as keys and arrays as values, containing all the items for that group.
Applies the classifier on items and groups those items into
a group for which the classifier returned the same value.
Equality is determined by ===
. The downstream collector is
then applied to the items of each group. The result is a map
between the key returned by the classifier and the value
returned by the downstream collector.
factory.stream(factory.times(11)).collect(Collectors.groupDown(x => x % 3, Collectors.sum()))
// => Map{0: 0+3+6+9, 1: 1+4+7+10, 2: 2+5+8}
// Returns a map between the city and the people living in that city.
factory.stream(people).groupDown(person => person.city, Collectors.toSet())
// => Map<City, Set<Person>>
Type of the items to be collected.
Type of the group key.
Type of the intermediate value use by the downstream.
Type of the group value.
Determines the group key of each item. Items with the same group key are grouped together.
Collector that is applied to the items of each group.
A collector that groups the items and then collects the items of each group.
Turns the items into strings and joins these strings together with the given delimiter. Optionally, if prefix or suffix is given, prepends or appends it to the result.
factory.stream(["foo", "bar"]).collect(Collectors.join())
// => "foobar"
factory.stream(["foo", "bar"]).collect(Collectors.join(","))
// => "foo,bar"
factory.stream(["foo", "bar"]).collect(Collectors.join(",", "[", "]"))
// => "[foo,bar]"
factory.stream([]).collect(Collectors.join(","))
// => ""
Type of the items to be collected.
A separator inserted between two items. Default to the empty string.
If given, it is prepended to the joined result.
If given, it is appended to the joined result.
A collector that joins the items into one string with the given delimiter, prefix and suffix.
Maps the items with the given mapper and passed them on to the given downstream collector.
const countLetters = Collectors.map(x => x.length), Collectors.sum();
factory.stream(["foo", "foobar"]).collect(countLetters)
// => 9
Type of the items to be collected.
Type of the mapped items.
Type of the intermediate value used by the downstream.
Type of the downstream result.
Mapping function applied to each item.
Collector that takes the mapped items.
The result of the given downstream collector.
Computes the product of all the collected items, ie.
(x_1 * x_2 * ... * x_n)
, where n
is the number of items
and the x_i
are the individual items. Returns NaN
when
there are no items.
factory.stream([]).collect(Collectors.multiply());
// => NaN
factory.stream([2, 4, 6]).collect(Collectors.multiply());
// => 48
const multiply = Collectors.multiply(x => x.length);
factory.stream(["is", "fish", "likely", "allergic"]).collect(multiply);
// => 384
Type of the items to be collected.
An optional converter for turning items into numbers. Default to item => Number(item)
.
A collector that converts each item into a number and multiplies them.
Splits the items into two groups according to the given discriminator.
factory.stream([-3,2,9,-4]).collect(Collectors.partition(x => x > 0))
// => { false: [-3,-4], true: [2,9]}
factory.stream([-3,2,9,-4]).collect(Collectors.partition(x => x > 0))
// => { false: [], true: []}
Type of the elements in the given iterable.
An object containing the partitioned items.
Applies the predicate on the items, grouping them in one of
two classes according to the result of the predicate. The
downstream collector is then applied to the items of each
group. The result is an object with the keys false
and true
and the value as returned by the downstream collector.
factory.stream(factory.times(11)).collect(Collectors.groupDown(x => x % 2 === 1, Collectors.sum()))
// => {false: 0+2+4+6+8+10, true: 1+3+5+7+9}
Type of the items to be collected.
Type of the intermediate value used by the downstream.
Type of the group result.
Collector that is applied to the items of each group.
A collector that partitions the items and then collects the items of the true
and false
group.
Computes the sum of all the collected items, ie.
(x_1 + x_2 + ... + x_n)
, where n
is the number of items and
the x_i
are the individual items. Returns NaN
when there are
no items.
factory.stream([]).collect(Collectors.sum());
// => NaN
factory.stream([1, 2, 3]).collect(Collectors.sum());
// => 6
const letterCount = Collectors.sum(x => x.length);
factory.stream(["fish", "and", "chips"]).collect(letterCount);
// => 12
Type of the items to be collected.
An optional converter for turning items into numbers. Default to item => Number(item)
.
A collector that converts each item into a number and computes their sum.
Computes a statistic for the items, such as the variance and the mean. Returns an instance of IStatistics, see IStatistics for an in-depth description.
factory.stream([]).collect(Collectors.summarize());
// => Statistics(count=3, mean=NaN, min=NaN, ...)
factory.stream([1,3,8]).collect(Collectors.summarize());
// => Statistics(count=3, mean=4, min=1, ...)
const letterAverage = Collectors.summarize(x => x.length);
factory.stream(["is", "fish", "likely", "allergic"]).collect(letterAverage);
// => Statistics(count=4, mean=5, min=2, ...)
Type of the items to be collected.
An optional converter for turning items into numbers. Default to item => Number(item)
.
A collector that converts each item into a number and computes statistics for these numbers.
Collects all items into an array, in the order in which the items are provided.
factory.stream().toArray()
// => []
factory.stream("foo").toArray()
// => ["f", "o", "o"]
Type of the items to be collected.
A collector that adds all items into an array.
Collects all items into a map. An item is added to the map with the key as returned by the key mapper and the value as returned by the value mapper.
When two items have the same key, the optional merge function is called with the two items and the result of the merge function is used as the value for that key. If no merge function is given, the value of the item encountered first is taken.
factory.stream().toMap(x=>x, x=>x)
// => Map()
const data = [{id: 0, name: "foo"}, {id: 0, name: "bar"}];
factory.stream(data).toMap(x => x.id, x => x.name)
// => Map[ 0 => "bar" ]
factory.stream(data).toMap(x => x.id, x => x.name, (name1, name2) => name1 + "," + name2)
// => Map[ 0 => "foo,bar" ]
Type of the items to be collected.
Type of the key of the map.
Type of the value of the map.
Takes an item and returns the key for that item.
Takes an items and returns the value for that item.
A merge function called when two items map to the same key and returns the merged value. Called with two items having the same key, the first argument is the item encountered first in the stream.
A collector that adds all items to a Map with the key and value as computed by the key and value mapper.
Collects all items into a set. Duplicate items are ignored.
factory.stream().toSet()
// => Set()
factory.stream("foo").toSet()
// => Set("f", "o")
Type of the items to be collected.
A collector that adds all items to a Set.
Generated using TypeDoc
Computes the (arithmetic) average of all the collected items, ie.
(x_1 + x_2 + ... + x_n)/n
, wheren
is the number of items and thex_i
are the individual items. ReturnsNaN
when there are no items.factory.stream([]).collect(Collectors.average()); // => NaN factory.stream([1, 2, 3]).collect(Collectors.average()); // => 2 const letterAverage = Collectors.sum(x => x.length); factory.stream(["fish", "and", "chips"]).collect(letterAverage); // => 4