Package: effect
Module: Option
Lifts a Predicate or Refinement into the Option context: returns
Some(value) when the predicate holds, None otherwise.
When to use
Use to convert a boolean check into an Option-returning function
OptionDetails
predicate(value) is true → Some(value)predicate(value) is false → NoneExample (Validating positive numbers)
import { Option } from "effect"
const parsePositive = Option.liftPredicate((n: number) => n > 0)
console.log(parsePositive(1))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
console.log(parsePositive(-1))
// Output: { _id: 'Option', _tag: 'None' }
See
filter to apply a predicate to an existing OptiontoRefinement for the inverse directionSignature
declare const liftPredicate: { <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>; <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>; <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>; <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>; }
Since v2.0.0