Package: effect
Module: Option
Converts an Option-returning function into a type guard (refinement).
When to use
Use when you need to turn an Option-returning parser into a type-narrowing
predicate, such as for Array.prototype.filter.
Details
true when the original function returns Somefalse when the original function returns NoneB on successExample (Converting a parser to a type guard)
import { Option } from "effect"
type MyData = string | number
const parseString = (data: MyData): Option.Option<string> =>
typeof data === "string" ? Option.some(data) : Option.none()
// ┌─── (a: MyData) => a is string
// ▼
const isString = Option.toRefinement(parseString)
console.log(isString("a"))
// Output: true
console.log(isString(1))
// Output: false
See
liftPredicate for the reverse directionSignature
declare const toRefinement: <A, B extends A>(f: (a: A) => Option<B>) => (a: A) => a is B
Since v2.0.0