whenOrElse<R> method
A when or else function for Enums. It takes a Map of Enums to functions, and returns the result of calling the function corresponding to the Enum of the object.
Implementation
R whenOrElse<R>(Map<Enum, R Function()> map, {required R Function() orElse}) {
if (map.containsKey(this)) {
return map[this]!();
} else {
return orElse();
}
}