#Type Alias: Option<T>
A union type representing either a Some or a None.
#Type Parameters
#T
T
The type of the Some value.
#Example
import { import Option Option } from 'byenull';
const const doSomething: () => Option.Option<number> doSomething = (): import Option Option .type Option<T> = Option.Some<T> | Option.NoneA union type representing either a
Some
or a
None
.
@typeParamT - The type of the Some value.@exampleimport { Option } from 'byenull';
const doSomething = (): Option.Option<number> => {
return Math.random() > 0.5
? Option.some(10)
: Option.none();
};
@categoryCore Types Option <number> => {
return var Math: MathAn intrinsic object that provides basic mathematics functionality and constants.
Math .Math.random(): numberReturns a pseudorandom number between 0 and 1.
random () > 0.5
? import Option Option .function some<number>(value: number): Option.Option<number>Creates a
Some
from a given value.
Passing null or undefined returns
None
instead.
@typeParamT - The type of the value to wrap.@returnsA Some containing the value, or None if the value is nullish.@exampleimport { Option } from 'byenull';
const some = Option.some(42);
// { type: 'Some', value: 42 }
const none = Option.some(null);
// { type: 'None' }
@categoryCreators some (10)
: import Option Option .function none(): Option.Option<never>Creates a
None
: an Option that holds no value.
@returnsA None.@exampleimport { Option } from 'byenull';
const option = Option.none();
// { type: 'None' }
@categoryCreators none ();
};