match
R
match<
Pattern match on nullable value with cases for non-null and null.
This provides a safe way to handle nullable values by requiring
explicit handling of both the present (some) and absent (none) cases.
Parameters:
some: Function called when this value is non-nullnone: Function called when this value is null
Returns: The result of calling either some or none
Example:
int? maybeNumber = 42;
final result = maybeNumber.match(
some: (n) => 'Number: $n',
none: () => 'No number',
); // Returns: "Number: 42"
Implementation
R match<R>({required R Function(T) some, required R Function() none}) =>
switch (this) {
final T value => some(value),
null => none(),
};