okOr method
Gets the Ok value or a default value if the result is not Ok.
defaultValue - The default value to be returned if not Ok.
filterNullish - Whether to filter out null values. If the snapshot
is ok but null, it will return defaultValue.
Example:
ok(42).okOr(100); // 42
err<int>(Exception()).okOr(100); // 100
pending<int>().okOr(100); // 100
ok<int?>(null).okOr(100, filterNullish: true); // 100
Implementation
T okOr(T defaultValue, {bool filterNullish = false}) {
return mapOrElse(
err: (_) => defaultValue,
pending: () => defaultValue,
ok: (x) => (filterNullish && x == null) ? defaultValue : x,
)!;
}