The input UnknownOptional type.
The type of the error value used for the None case.
Ok with the contained value, or Err with error.
assert.deepStrictEqual(
Result.fromOptional(Optional.some(42), 'missing'),
Result.ok(42),
);
assert.deepStrictEqual(
Result.fromOptional(Optional.none, 'missing'),
Result.err('missing'),
);
const withMissingError = Result.fromOptional('missing');
assert.deepStrictEqual(withMissingError(Optional.some(1)), Result.ok(1));
assert.deepStrictEqual(
withMissingError(Optional.none),
Result.err('missing'),
);
Converts an Optional to a Result (the inverse of
Result.toOptional, and the equivalent of Rust's Option::ok_or).
If the Optional is Some, returns Ok with the contained value.
If it is None, returns Err with the provided error value.
The type of the error value used for the None case.
The error value to use if the Optional is None.
Ok with the contained value, or Err with error.
assert.deepStrictEqual(
Result.fromOptional(Optional.some(42), 'missing'),
Result.ok(42),
);
assert.deepStrictEqual(
Result.fromOptional(Optional.none, 'missing'),
Result.err('missing'),
);
const withMissingError = Result.fromOptional('missing');
assert.deepStrictEqual(withMissingError(Optional.some(1)), Result.ok(1));
assert.deepStrictEqual(
withMissingError(Optional.none),
Result.err('missing'),
);
Converts an Optional to a
Result(the inverse of Result.toOptional, and the equivalent of Rust'sOption::ok_or).If the Optional is
Some, returnsOkwith the contained value. If it isNone, returnsErrwith the provided error value.