createSelector5<S, R1, R2, R3, R4, R5, T> function

Selector<S, T> createSelector5<S, R1, R2, R3, R4, R5, T>(
  1. Selector<S, R1> selector1,
  2. Selector<S, R2> selector2,
  3. Selector<S, R3> selector3,
  4. Selector<S, R4> selector4,
  5. Selector<S, R5> selector5,
  6. T combiner(
    1. R1,
    2. R2,
    3. R3,
    4. R4,
    5. R5
    ),
  7. {T Function(R1, R2, R3, R4, R5) memoize(
    1. T (
      1. R1,
      2. R2,
      3. R3,
      4. R4,
      5. R5
      )
    )?}
)

Create a memoized selector by combining five selectors. It will cache the result of the combiner function, and only recompute when the provided selectors deliver new results.

A complete example can be seen as part of the Selector documentation.

Implementation

Selector<S, T> createSelector5<S, R1, R2, R3, R4, R5, T>(
  Selector<S, R1> selector1,
  Selector<S, R2> selector2,
  Selector<S, R3> selector3,
  Selector<S, R4> selector4,
  Selector<S, R5> selector5,
  T Function(R1, R2, R3, R4, R5) combiner, {
  T Function(R1, R2, R3, R4, R5) Function(T Function(R1, R2, R3, R4, R5))?
      memoize,
}) {
  final memoized = (memoize ?? memo5)(combiner);

  return (S state) {
    return memoized(
      selector1(state),
      selector2(state),
      selector3(state),
      selector4(state),
      selector5(state),
    );
  };
}