The input UnknownOptional type.
The type of the value returned by the mapping function.
A new Optional<S2> resulting from the mapping, or
None if the input was None.
const numberOptional = Optional.some(21);
const mapped = Optional.map(numberOptional, (value) => value * 2);
assert.deepStrictEqual(mapped, Optional.some(42));
const mapToLength = Optional.map((text: string) => text.length);
assert.deepStrictEqual(mapToLength(Optional.some('abc')), Optional.some(3));
assert.deepStrictEqual(mapToLength(Optional.none), Optional.none);
Maps an Optional to OptionalmapFn to the
value in Some and returns a new Some with the result.
The type of the value returned by the mapping function.
A new Optional<S2> resulting from the mapping, or
None if the input was None.
const numberOptional = Optional.some(21);
const mapped = Optional.map(numberOptional, (value) => value * 2);
assert.deepStrictEqual(mapped, Optional.some(42));
const mapToLength = Optional.map((text: string) => text.length);
assert.deepStrictEqual(mapToLength(Optional.some('abc')), Optional.some(3));
assert.deepStrictEqual(mapToLength(Optional.none), Optional.none);
Maps an Optional
to Optional by applying a function to
a contained value. If the Optional is None, it
returns Optional.none. Otherwise, it applies the mapFnto the value inSomeand returns a newSomewith the result.