Option65
Constructors
Models
NoneinterfaceRepresents the absence of a value within an Option.OptiontypeThe Option data type represents optional values.OptionUnifyinterfaceType-level unification support for Option values.OptionUnifyIgnoreinterfaceMarker interface used by Effect's Unify machinery for Option values.SomeinterfaceRepresents the presence of a value within an Option.Guards
Getters
Elements
containsconstChecks whether an Option contains a value equal to the given one, using default structural equality.containsWithconstChecks whether an Option contains a value equivalent to the given one, using a custom Equivalence.existsconstChecks whether the value in a Some satisfies a predicate or refinement.Mapping
Filtering
Sequencing
andThenconstChains a second computation onto an Option.composeKconstComposes two Option-returning functions into a single function that chains them together.flatMapconstApplies a function that returns an Option to the value of a Some, flattening the result.flatMapNullishOrconstCombines flatMap with fromNullishOr: applies a function that may return null/undefined to the value of a Some.flattenconstFlattens a nested Option<Option<A>> into Option<A>.tapconstRuns a side-effecting Option-returning function on the value of a Some, returning the original Option if the function returns Some, or None if it returns None.Combiner
Combining
allconstCombines a structure of Options (tuple, struct, or iterable) into a single Option containing the unwrapped structure.productconstCombines two Options into a Some containing a tuple [A, B] if both are Some.productManyconstCombines a primary Option with an iterable of Options into a tuple if all are Some.Converting
fromNullishOrconstConverts a nullable value (null or undefined) into an Option.fromNullOrconstConverts a possibly null value into an Option, leaving undefined as a valid Some.fromUndefinedOrconstConverts a possibly undefined value into an Option, leaving null as a valid Some.getFailureconstConverts a Result into an Option, keeping only the failure value.getOrThrowconstExtracts the value from a Some, or throws a default Error for None.getOrThrowWithconstExtracts the value from a Some, or throws a custom error for None.getSuccessconstConverts a Result into an Option, keeping only the success value.liftNullishOrconstLifts a function that may return null or undefined into one that returns an Option.liftThrowableconstLifts a function that may throw into one that returns an Option.toArrayconstConverts an Option into an Array.toRefinementconstConverts an Option-returning function into a type guard (refinement).Do Notation
Error Handling
firstSomeOfconstReturns the first Some found in an iterable of Options, or None if all are None.orElseconstReturns the fallback Option if self is None; otherwise returns self.orElseResultconstReturns the first available value and marks whether it came from the fallback.orElseSomeconstReturns Some of the fallback value if self is None; otherwise returns self.