whenValue<V, T> function
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,Map,Set,以及Iterable。
只要conditionMap
的Map.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();
}