the item type
Used by the node REPL to display values.
View this Some a as Option. Useful to help typescript type inference sometimes.
Returns true if the option is a Some and contains the value you give, false otherwise.
Two objects are equal if they represent the same value, regardless of whether they are the same object physically in memory.
If this is None, will return None. If it's a Some, and the contents match your predicate, return the option. If the contents don't match the predicate, return None.
Get the value from this option; if it's a None (no value present), then return the value returned by the function that you give.
Option.of(5).getOrCall(() => 6)
=> 5
Option.none<number>().getOrCall(() => 6)
=> 6
Get the value from this option; if it's a None (no value present), then return the default value that you give.
Get the value contained in the option if it's a Some, return null if it's a None.
Option.of(5).getOrNull()
=> 5
Option.none<number>().getOrNull()
=> null
Get the value from this option if it's a Some, otherwise throw an exception. You can optionally pass a message that'll be used as the exception message, or an Error object.
Get the value contained in the option if it's a Some, return undefined if it's a None.
Option.of(5).getOrUndefined()
=> 5
Option.none<number>().getOrUndefined()
=> undefined
Get a number for that object. Two different values may get the same number, but one value must always get the same number. The formula can impact performance.
Execute a side-effecting function if the option is a Some; returns the option.
Execute a side-effecting function if the option is a Some; returns the option.
Returns true since this is a None (doesn'tcontains a value)
Returns false since this is a None (doesn'tcontains a value)
Return a new option where the element (if present) was transformed by the mapper function you give. If the option was None it'll stay None.
Option.of(5).map(x => x*2)
=> Option.of(10)
Option.of(5).map(x => null)
=> Option.of(null)
Also see None.mapNullable, None.flatMap
Return a new option where the element (if present) was transformed
by the mapper function you give. If the mapped value is null
or
undefined
, then a Some will turn into a None.
If the option was None it'll stay None.
Option.of(5).mapNullable(x => x*2)
=> Option.of(10)
Option.of(5).mapNullable(x => null)
=> Option.none()
Also see None.map, None.flatMap
Handle both branches of the option and return a value (can also be used for side-effects). This is the catamorphism for option.
Option.of(5).match({
Some: x => "got " + x,
None: () => "got nothing!"
});
=> "got 5"
Convert to an either. You must provide a left value in case this is a None.
Get a human-friendly string representation of that value.
Convert to a vector. If it's a None, it's the empty vector, if it's a Some, it's a one-element vector with the contents of the option.
Transform this value to another value type. Enables fluent-style programming by chaining calls.
Generated using TypeDoc
None represents an Option without value. "static methods" available through OptionStatic
Some and None have the same methods, except that Some has the extra Some.get method that None doesn't have.