when<T> method
T
when<T>({})
Executes the given callback when [this.value is of the type parameter.
Implementation
T when<T>({
required T Function(Map<String, Json>) map,
required T Function(List<Json>) list,
required T Function(num) number,
required T Function(bool) boolean,
required T Function(String) str,
required T Function(Null) none,
}) {
final v = this;
if (v is JsonMap) {
return map(v.value);
} else if (v is JsonList) {
return list(v.value);
} else if (v is JsonNumber) {
return number(v.value);
} else if (v is JsonBoolean) {
return boolean(v.value);
} else if (v is JsonStr) {
return str(v.value);
} else if (v is JsonNone) {
return none(null);
}
throw Error();
}