Options
All
  • Public
  • Public/Protected
  • All
Menu

A collector takes all items of a stream and incorporates them into a single object. It does this by first creating an intermediate container (eg. a Set), then processing all items (eg. adding them to the Set), and finally converting the intermediate value to the resulting value (eg. the size of the set).

function toSetT>(): Collector<T, any, Set<T>> {
  accumulator(intermediate: T[], item: T) {
    intermediate.push(item);
  },
  supplier(): T[] {
    return [];
  },
  finisher(intermediate: T[]): Set<T> {
    return new Set(intermediate);
  },
};

stream([1,2,3]).map(x => 2*x).collect(toSet());

Type parameters

  • S

    Type of the items to be collected.

  • T

    Type of the intermediate object used while collecting.

  • R

    Type of the collected object.

Hierarchy

  • Collector

Index

Properties

accumulator

accumulator: BiConsumer<T, S>

Takes the intermediate object and the current object; and incorporates the current object into the intermediate object.

finisher

finisher: TypedFunction<T, R>

Transform the intermediate object into the final result.

supplier

supplier: Supplier<T>

Creates a new intermediate object.

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc