carbonteq /FP

Option extras

Option-specific operators and constructors for filtering, combining, and converting optional values.

These operators are available only on Option and help with filtering, combining multiple options, and converting to Result.

Option-only operators

OperatorDescriptionUsage
filterKeep value only if predicate passes
Some(v).filter(pred) → Some/None
Option.allCombine Options; Some if all are Some
Option.all(o1, o2, ...) → Some([...])
Option.anyFirst Some wins, or None
Option.any(o1, o2, ...) → first Some
toResultConvert to Result with error for None
Some(v).toResult(err) → Ok(v)
matchPattern match on Option state
opt.match({ Some, None })

Constructors

OperatorDescriptionUsage
Option.SomeCreate a Some containing a value
Option.Some(val)
Option.NoneSingleton None instance
Option.None
Option.fromNullableNone for null/undefined
fromNullable(val)
Option.fromFalsyNone for any falsy value
fromFalsy(val)
Option.fromPredicateSome if predicate passes
fromPredicate(val, pred)

Notes

  • fromFalsy treats false, 0, "", null, undefined as None.
  • filter supports async predicates; use .toPromise() to resolve.
  • match is an instance method; for standalone matching use matchOpt.

On this page