whenValue<V, T> function

T? whenValue<V, T>(
  1. V value,
  2. Map<V, ValueGetter<T>> conditionMap
)

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:

T? kind = whenValue<T>(
  V,
  {
    V: () {
      return T;
    },
    V: () {
      return T;
    },
    V: () {
      return T;
    },
  },
);

Implementation

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