whenValueSafe<V, T> function

T whenValueSafe<V, T>(
  1. V value,
  2. Map<V, ValueGetter<T>> conditionMap, {
  3. ValueGetter<T>? defaultValue,
})

English: The super evolution version💖💖💖 of switch method, all basic types of values can be compared, including List, Map, Set, and Iterable.
All need do is value in Map.keys of conditionMap, its corresponding ValueGetter method will be executed

中文: 方法switch的超级进化版本💖💖💖,所有基本类型的value都可以比较,包括List,MapSet,以及Iterable
只要conditionMapMap.keys中有value的话,就会执行其对应的ValueGetter方法

example:

String kind = whenValue<List, String>(
  ["apple", "orange"],
  {
    ["cat", "dog"]: () {
      return "pets";
    },
    ["apple", "orange"]: () {
      return "fruits";
    },
    ["red", "white", "black"]: () {
      return "colors";
    },
  },
);

Implementation

T whenValueSafe<V, T>(V value, Map<V, ValueGetter<T>> conditionMap,
    {ValueGetter<T>? defaultValue}) {
  return (conditionMap.entries
              .firstOrNullWhere((element) =>
                  const DeepCollectionEquality().equals(element.key, value))
              ?.value ??
          defaultValue)!
      .call();
}