cache2states<Result, State1, State2> function Null safety

Result Function() Function(State1, State2) cache2states<Result, State1, State2>(
  1. Result Function() f(
    1. State1,
    2. State2
    )
)

Cache for 2 immutable states, and no parameters.

The first time this function is called with some states, it will calculate the result from them, and then return the result. When this function is called again with the same states (compared with the previous ones by IDENTITY) it will return the same result, without having to calculate again. When this function is called again with any of the states (or both) different from the previous ones, it will evict the cache, recalculate the result, and cache it.

Example:

var selector = cache2((List<String> names, int limit) =>
       () => names.where((str) => str.startsWith("A")).take(limit).toList());

Implementation

Result Function() Function(State1, State2) cache2states<Result, State1, State2>(
  Result Function() Function(State1, State2) f,
) =>
    c.cache2states(f);