<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>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
- Validating input and wrapping it in
Option
Details
predicate(value)istrue→Some(value)predicate(value)isfalse→None- Supports refinements for type narrowing
Example (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' }export const 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>
}
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
- Validating input and wrapping it in
Option
Details
predicate(value) is true → Some(value)
predicate(value) is false → None
- Supports refinements for type narrowing
Example (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' }
liftPredicate: { // Note: I intentionally avoid using the NoInfer pattern here.
<function (type parameter) A in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>A, function (type parameter) B in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>B extends function (type parameter) A in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>A>(refinement: Refinement<A, B>refinement: interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) A in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>A, function (type parameter) B in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>B>): (a: Aa: function (type parameter) A in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>A) => type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <A, B extends A>(refinement: Refinement<A, B>): (a: A) => Option<B>B>
<function (type parameter) B in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>B extends function (type parameter) A in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>A, function (type parameter) A in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>A = function (type parameter) B in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>B>(predicate: Predicate<A>predicate: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>A>): (b: B extends Ab: function (type parameter) B in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>B) => type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <B extends A, A = B>(predicate: Predicate<A>): (b: B) => Option<B>B>
<function (type parameter) A in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>A, function (type parameter) B in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>B extends function (type parameter) A in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>A>(
self: Aself: function (type parameter) A in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>A,
refinement: Refinement<A, B>refinement: interface Refinement<in A, out B extends A>A predicate that also narrows the input type when it returns true.
When to use
Use when you want a runtime check that refines A to B for TypeScript,
especially when composing type guards with
compose
or safely
checking unknown values.
Details
A refinement returns a type predicate (a is B). Use it with if or
filter to narrow types.
Example (Narrowing unknown values)
import { Predicate } from "effect"
const isString: Predicate.Refinement<unknown, string> = (u): u is string => typeof u === "string"
const data: unknown = "hello"
if (isString(data)) {
console.log(data.toUpperCase())
}
Type-level utilities for working with
Refinement
types.
When to use
Use when you need to extract input and output types from refinement
signatures while writing generic helpers over refinements.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting refinement types)
import { Predicate } from "effect"
type IsString = Predicate.Refinement<unknown, string>
type Input = Predicate.Refinement.In<IsString>
type Output = Predicate.Refinement.Out<IsString>
Refinement<function (type parameter) A in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>A, function (type parameter) B in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>B>
): type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <A, B extends A>(self: A, refinement: Refinement<A, B>): Option<B>B>
<function (type parameter) B in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>B extends function (type parameter) A in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>A, function (type parameter) A in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>A = function (type parameter) B in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>B>(
self: B extends Aself: function (type parameter) B in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>B,
predicate: Predicate<A>predicate: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>A>
): type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <B extends A, A = B>(self: B, predicate: Predicate<A>): Option<B>B>
} = import dualdual(
2,
<function (type parameter) B in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>B extends function (type parameter) A in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>A, function (type parameter) A in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>A = function (type parameter) B in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>B>(b: B extends Ab: function (type parameter) B in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>B, predicate: Predicate<A>predicate: interface Predicate<in A>A function that decides whether a value of type A satisfies a condition.
When to use
Use when you want a reusable boolean check for A, especially when you plan
to combine checks with
and
/
or
or pass a predicate to arrays
and iterables.
Details
A predicate returns true or false and never throws by itself. It does not
narrow types unless you use Refinement.
Example (Defining a predicate)
import { Predicate } from "effect"
const isPositive: Predicate.Predicate<number> = (n) => n > 0
console.log(isPositive(1))
Type-level utilities for working with
Predicate
types.
When to use
Use when you need to extract input types from predicate signatures while
writing generic helpers over predicate types.
Details
These utilities are type-only, create no runtime values, and the namespace is
erased at runtime.
Example (Extracting predicate input)
import { Predicate } from "effect"
type IsString = Predicate.Predicate<string>
type Input = Predicate.Predicate.In<IsString>
Predicate<function (type parameter) A in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>A>): type Option<A> = None<A> | Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) B in <B extends A, A = B>(b: B, predicate: Predicate<A>): Option<B>B> => predicate: Predicate<A>predicate(b: B extends Ab) ? const some: <A>(value: A) => Option<A>Wraps the given value into an Option to represent its presence.
When to use
Use to wrap a known present value as Option
- Returning a successful result from a partial function
Details
- Always returns
Some<A>
- Does not filter
null or undefined; use
fromNullishOr
for that
Example (Wrapping a value)
import { Option } from "effect"
// ┌─── Option<number>
// ▼
const value = Option.some(1)
console.log(value)
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
some(b: B extends Ab) : const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()
)