The type of the value.
Returns the other option if this option is Some.
let option = some('example');
let other = some(123);
let result = option.and(other);
assert(result === other);
If this option is None, then None is returned.
option = none();
result = option.and(other);
assert(result.isNone() === true);
The type of the value in the other option.
The other option.
The other option, or None.
Maps and returns this option if it is Some.
let option = some('example');
let fn = v => some(v.length);
let result = option.andThen(fn);
assert(result.unwrap() === 7);
If this option is None, then None is returned.
option = none();
result = option.andThen(fn);
assert(result.isNone() === true);
The type of the computed value.
The mapped option, or None.
Returns the value in this option if it is Some.
let error = 'The example error message.';
let option = some('example');
let result = option.expect(error);
assert(result === 'example');
If this option is None, then an error is thrown.
option = none();
result = option.expect(error);
// error thrown using given message
The error message.
The value in this option.
Returns this option if the predicate returns true.
let option = some('example');
let predicate = o => o === 'example';
let result = option.filter(predicate);
assert(result === option);
If the predicate returns false, then None is returned.
option = some('other');
result = option.filter(predicate);
assert(result.isNone() === true);
If the option is None, then None is returned.
option = none();
result = option.filter(predicate);
assert(result.isNone() === true);
The predicate to apply.
This option or None.
Returns the value in this option if Some.
let option = some('example');
let other = 'other';
let result = option.getOrInsert(other);
assert(result === 'example');
If this option is None, this option becomes Some and the given value is set and returned.
option = none();
result = option.getOrOinsert(other);
assert(result === other);
assert(option.isSome() === true);
assert(option.unwrap() === other);
The value to insert.
The value in this option or the given value.
Returns the value in this option if Some.
let option = some('example');
let other = () => 'other';
let result = option.getOrInsertWith(other);
assert(result === 'example');
If this option is None, the value is produced and this option becomes Some with the
produced value set. The produced value is then returned.
option = none();
result = option.getOrOinsertWith(other);
assert(result === 'other');
assert(option.isSome() === true);
assert(option.unwrap() === other);
The producer for value to insert.
The value in this option or the given value.
Returns true if this option is None.
let option = none();
assert(option.isNone() === true);
If this option is None, then true. Otherwise, false.
Returns true if the option is Some.
let option = some('example');
assert(option.isSome() === true);
If this option is Some, then true. Otherwise, false.
Returns the mapped option if this option is Some.
let fn = o => o.length;
let option = some('example');
let result = option.map(fn);
assert(result.unwrap() === 7);
If this option is None, then None is returned.
The type of the computed value.
The mapping function.
The mapped option or None.
Returns the mapped value if this option is Some.
let def = 456;
let fn = o => o.length;
let option = some('example');
let result = option.mapOr(def, fn);
assert(result.unwrap() === 7);
If the option is None, then the default value is returned.
option = none();
result = option.mapOr(def, fn);
assert(result.unwrap() === 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 option is Some.
let def = () => 456;
let fn = o => o.length;
let option = some('example');
let result = option.mapOrElse(def, fn);
assert(result.unwrap() === 7);
If this option is None, then the default value is produced and returned.
option = none();
result = option.mapOrElse(def, fn);
assert(result.unwrap() === 456);
The type of the computed or default value.
The mapped or default value.
Transforms this option into Ok<T, E> if it is `Some.
let error = 'error';
let option = some('example');
let result = option.okOr(error);
assert(result.isOk() === true);
If this option is None, the option is transformed into Err<T, E>.
option = none();
result = option.okOr(error);
assert(result.isErr() === true);
The type of the error value.
The possible error.
The result.
Transforms this Option<T> into Ok<T, E> if it is Some.
let error = () => 'error';
let option = some('example');
let result = option.okOrElse(error);
assert(result.isOk() === true);
If this option is None, the Err<T, E> is produced and returned.
option = none();
result = option.okOrElse(error);
assert(result.isErr() === true);
The type of the error value.
The producer for the possible error.
The result.
Returns this option if Some.
let option = some('example');
let other = some('other');
let result = option.or(other);
assert(result === option);
If this option is None, the other option is returned.
option = none();
result = option.or(other);
assert(result === other);
The other option.
This or the other option.
Returns this option if Some.
let option = some('example');
let fn = () => some('other');
let result = option.orElse(fn);
assert(result === option);
If this option is None, the other option is produced and returned.
option = none();
result = option.orElse(fn);
assert(result.unwrap() === 'other);
This or the other option.
Replaces the value in this option and returns the old one.
let option = some('example');
let result = option.replace('other');
assert(result.unwrap() === 'example');
assert(option.unwrap() === 'other');
If this option is None, it will be converted to Some.
option = none();
result = option.replace('other');
assert(result.isNone() === true);
assert(option.isSome() === true);
assert(option.unwrap() === 'other');
The new value.
The old value.
Returns the value in this option.
let option = some('example');
let result = option.unwrap();
assert(result === 'example');
The value.
Returns the value in this option if Some.
let def = 'default';
let option = some('example');
let result = option.unwrapOr(def);
assert(result === 'example');
If this option is None, the default value is returned.
option = none();
result = option.unwrapOr(def);
assert(result === def);
The default value.
The unwrapped or default value.
Returns this value in this option if Some.
let fn = () => 'default';
let option = some('example');
let result = option.unwrapOrElse(fn);
assert(result === 'example');
If this option is None, the default value is produced and returned.
option = none();
result = option.unwrapOrElse(fn);
assert(result === 'default');
The producer for the default value.
The unwrapped or default value.
Returns this option if Some and the other option is None.
let option = some('example');
let other = none();
let result = option.xor(other);
assert(result === option);
If this option is None and the other option is Some, the other option is returned.
option = none();
other = some('other');
result = option.xor(other);
assert(result === other);
If this option is Some and the other option is Some, then None is returned.
option = some('example');
other = some('other');
result = option.xor(other);
assert(result.isNone() === true);
The other option.
This option, the other option, or None.
Returns this option and the other option, if both are Some, into a new Some.
let option = some('example');
let other = some('other');
let result = option.zip(other);
assert(result.isSome() === true);
let values = result.unwrap();
assert(values[0] === 'example');
assert(values[1] === 'other');
The type of the value in the other option.
The other option.
The zipped option or None.
Generated using TypeDoc
Manages access to a value that may or may not be present.