split<R> method
R
split<R>()
Handle each possible shape of this JSON value.
This method is used to discriminate the possible shapes of
this JSON value, similarly to a switch expression. It accepts
one function per shape, unconditionally, and using positional
parameters. This is the most concise approach. Use splitNamed
if a more flexible (but less concise) approach is preferred.
In the case where this JSON value is malformed (i.e., it is not of
type Null, bool, int, double, String, List<dynamic>,
or Map<String, dynamic>), an InvalidJsonTypeException is
thrown, holding the given value.
Implementation
R split<R>(
R Function() onNull,
R Function(bool) onBool,
R Function(int) onInt,
R Function(double) onDouble,
R Function(String) onString,
R Function(List<Json>) onList,
R Function(Map<String, Json>) onMap,
) {
var v = value;
if (v == null) return onNull();
if (v is bool) return onBool(v);
if (v is int) return onInt(v);
if (v is double) return onDouble(v);
if (v is String) return onString(v);
if (v is List<Json>) return onList(v);
if (v is Map<String, Json>) return onMap(v);
throw InvalidJsonTypeException(value);
}