fold method

  1. @override
Result<Option<Object>> fold(
  1. @noFutures Option<Object>? onSome(
    1. Some<T> some
    ),
  2. @noFutures Option<Object>? onNone(
    1. None<T> none
    )
)
override

Folds the two cases of this Option into a single Result.

The onSome and onNone functions must return a new Option.

Implementation

@override
@pragma('vm:prefer-inline')
Result<Option<Object>> fold(
  @noFutures Option<Object>? Function(Some<T> some) onSome,
  @noFutures Option<Object>? Function(None<T> none) onNone,
) {
  try {
    return Ok(onSome(this) ?? this);
  } catch (error) {
    return Err(error);
  }
}