cache2states_1param<Result, State1, State2, Param1> function Null safety

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

Cache for 2 immutable states, and 1 parameter.

When this function is called with some states and a parameter, it will check if it has the cached result for this states/parameter combination. If so, it will return it from the cache, without having to recalculate it again. If the result for this states/parameter combination is not yet cached, it will calculate it, cache it, and then return it. Note: The cache has one entry for each different parameter (comparing parameters by EQUALITY).

Cache eviction: Each time this function is called with some states, it will compare them (by IDENTITY) with the states from the previous time the function was called. If any of the states is different, the cache (for all parameters) will be evicted. In other words, as soon as one of the states (or both) change, it will clear all cached results and start all over again.

Example:

var selector = cache2states_1param((List<String> names, int limit) => (String searchString) {
   return names.where((str) => str.startsWith(searchString)).take(limit).toList();
   });

Implementation

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