createSelector2<S, R1, R2, T> function

Selector<S, T> createSelector2<S, R1, R2, T>(
  1. Selector<S, R1> selector1,
  2. Selector<S, R2> selector2,
  3. T combiner(
    1. R1,
    2. R2
    ), {
  4. T Function(R1, R2) memoize(
    1. T (
      1. R1,
      2. R2
      )
    )?,
})

Create a memoized selector by combining two 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> createSelector2<S, R1, R2, T>(
  Selector<S, R1> selector1,
  Selector<S, R2> selector2,
  T Function(R1, R2) combiner, {
  T Function(R1, R2) Function(T Function(R1, R2))? memoize,
}) {
  final memoized = (memoize ?? memo2)(combiner);

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