The type of the success value.
The type of the failure value.
Returns the other
result if this result is Ok
.
let result = ok('example');
let other = ok('other');
let output = result.and(other);
assert(output === other);
If this result is Err
, then this result is returned.
result = err(123);
output = result.and(other);
assert(output === result);
The type of the value in the other result.
The other result.
The other
result or this Err
.
Returns the computed other
result if this result is Ok
.
let result = ok('example');
let fn = r => ok(r + ' other');
let output = result.andThen(fn);
assert(output.unwrap() === 'example other');
If this result is Err
, then this result is returned.
result = err(123);
output = result.andThen(fn);
assert(output === result);
The type of the value in the computed result.
The other
result or this Err
.
Transforms this Result<T, E>
into Some<E>
if it is Err
.
let result = err(123);
let output = result.err();
assert(output.isSome() === true);
assert(output.unwrap() === 123);
If this result is Ok
, then None<E>
is returned.
result = ok('example');
output = result.err();
assert(output.isNone());
The option.
Returns the value in this result if Ok
.
let message = 'Example error message.';
let result = ok('example');
let output = result.expect(message);
assert(output === 'example');
If this result is Err
, an error is thrown.
result = err(123);
output = result.expect(message);
// throws error
The error message.
The value.
Returns the value in this result if Err
.
let message = 'Example error message.';
let result = err(123);
let output = result.expectErr(message);
assert(output === 123);
If this result is Ok
, an error is thrown.
result = ok('example');
output = result.expectErr(message);
// throws error
The error message.
The value.
Returns true
if this result is Error
.
let result = err(123);
let output = result.isErr();
assert(output === true);
If this result is Ok
, then false
is returned.
result = ok('example');
output = result.isErr();
assert(output === false);
Returns true
if Err
, or false
if not.
Returns true
if this result is Ok
.
let result = ok('example');
let output = result.isOk();
assert(output === true);
If this result is Err
, then false
is returned.
result = err(123);
output = result.isOk();
assert(output === false);
Returns true
if Ok
, or false
if not.
Returns the mapped result if this result is `Ok.
let fn = r => r.length;
let result = ok('example');
let output = result.map(fn);
assert(output.isOk() === true);
assert(output.unwrap() === 7);
If this result is Err
, this result is returned.
result = err(123);
output = result.map(fn);
assert(output === result);
The type of the value in the computed result.
The mapping function.
The result.
Returns the mapped result if this result is Err
.
let fn = r => r + 111;
let result = err(123);
let output = result.mapErr(fn);
assert(output.isErr() === true);
assert(output.unwrap() === 456);
If this result is Ok
, this result is returned.
result = ok('example');
output = result.mapErr(fn);
assert(output === result);
The type of the error in the computed result.
The mapping function.
The mapped result or this result.
Returns the mapped value if this result is Ok
.
let def = 456;
let fn = r => r.length;
let result = ok('example');
let output = result.mapOr(def, fn);
assert(output === 7);
If this result is Err
, then the default value is returned.
result = err(123);
output = result.mapOr(def, fn);
assert(output === 456);
The type of the computed or default value.
The default value.
The mapping function.
The mapped or default value.
Returns the mapped value if this result is Ok
.
let def = r => r + 333;
let fn = r => r.length;
let result = ok('example');
let output = result.mapOrElse(def, fn);
assert(output === 7);
If this result is Err
, then the default value is computed and returned.
result = err(123);
output = result.mapOrElse(def, fn);
assert(output === 456);
The type of the computed or default value.
The mapped or computed default value.
Converts this result to Some<T>
if this result is Ok
.
let result = ok('example');
let output = result.ok();
assert(output.isSome() === true);
assert(output.unwrap() === 'example');
If this result is Err
, then None<T>
is returned.
result = err(123);
output = result.ok();
assert(output.isNone() === true);
Returns Some
if Ok
, or None
if Error
.
Returns this result if this result is Ok
.
let other = ok('other');
let result = ok('example');
let output = result.or(other);
assert(output === result);
If this result is Err
, then the other result is returned.
result = err(123);
output = result.or(other);
assert(output === other);
If both this and the other result is Err
, the other result is returned.
other = err(456);
result = err(123);
output = result.or(other);
assert(output === other);
The type of the error in the computed result.
The other result.
This or the other result.
Returns this result if this result is Ok
.
let fn = () => ok('default');
let result = ok('example');
let output = result.orElse(fn);
assert(output === result);
If this result is Err
, then the default result is computed and returned.
result = err(123);
output = result.orElse(fn);
assert(output === 'default');
The type of the error in the computed result.
This or the default result.
Returns the value in this result if this result is Ok
.
let result = ok('example');
let output = result.unwrap();
assert(output === 'example');
If this result is Err
, an error is thrown.
result = err(123);
output = result.unwrap();
// throws error
The value.
Returns the value in this result if this result is Err
.
let result = err(123);
let output = result.unwrapErr();
assert(output === 123);
If this result is Ok
, an error is thrown.
result = ok('example');
output = result.unwrapErr();
// throws error
The value.
Returns the value in this result if this result is Ok
.
let def = 'default';
let result = ok('example');
let output = result.unwrapOr(default);
assert(output === 'example');
If this result is Err
, then the default value is returned.
result = err(123);
output = result.unwrapOr(default);
assert(output === def);
The default value.
The value in this result or the default value.
Returns the value in this result if this result is Ok
.
let fn = () => 'default';
let result = ok('example');
let output = result.unwrapOrElse(fn);
assert(output === 'example');
If this result is Err
, then the default value is computed and returned.
result = err(123);
output = result.unwrapOrElse(fn);
assert(output === 'default');
The default value computer.
The value in this result or the default value.
Generated using TypeDoc
Manages access to a value that represents either success (
Ok
) or failure (Err
).