<A, B extends A>(refinement: Refinement<A, B>): (
self: Option<A>
) => Option<B>
<A>(predicate: Predicate<A>): <B extends A>(self: Option<B>) => Option<B>
<A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>
<A>(self: Option<A>, predicate: Predicate<A>): Option<A>Filters an Option using a predicate. Returns None if the predicate is
not satisfied or the input is None.
When to use
Use when you need to discard an Option's present value when it does not
meet a condition, while narrowing the type via a refinement predicate.
Details
None→NoneSomewherepredicate(value)istrue→Some(value)Somewherepredicate(value)isfalse→None- Supports refinements for type narrowing
Example (Filtering with a predicate)
import { Option } from "effect"
const removeEmpty = (input: Option.Option<string>) =>
Option.filter(input, (value) => value !== "")
console.log(removeEmpty(Option.some("hello")))
// Output: { _id: 'Option', _tag: 'Some', value: 'hello' }
console.log(removeEmpty(Option.some("")))
// Output: { _id: 'Option', _tag: 'None' }
console.log(removeEmpty(Option.none()))
// Output: { _id: 'Option', _tag: 'None' }export const const filter: {
<A, B extends A>(
refinement: Refinement<A, B>
): (self: Option<A>) => Option<B>
<A>(predicate: Predicate<A>): <B extends A>(
self: Option<B>
) => Option<B>
<A, B extends A>(
self: Option<A>,
refinement: Refinement<A, B>
): Option<B>
<A>(
self: Option<A>,
predicate: Predicate<A>
): Option<A>
}
Filters an Option using a predicate. Returns None if the predicate is
not satisfied or the input is None.
When to use
Use when you need to discard an Option's present value when it does not
meet a condition, while narrowing the type via a refinement predicate.
Details
None → None
Some where predicate(value) is true → Some(value)
Some where predicate(value) is false → None
- Supports refinements for type narrowing
Example (Filtering with a predicate)
import { Option } from "effect"
const removeEmpty = (input: Option.Option<string>) =>
Option.filter(input, (value) => value !== "")
console.log(removeEmpty(Option.some("hello")))
// Output: { _id: 'Option', _tag: 'Some', value: 'hello' }
console.log(removeEmpty(Option.some("")))
// Output: { _id: 'Option', _tag: 'None' }
console.log(removeEmpty(Option.none()))
// Output: { _id: 'Option', _tag: 'None' }
filter: {
<function (type parameter) A in <A, B extends A>(refinement: Refinement<A, B>): (self: Option<A>) => Option<B>A, function (type parameter) B in <A, B extends A>(refinement: Refinement<A, B>): (self: Option<A>) => Option<B>B extends function (type parameter) A in <A, B extends A>(refinement: Refinement<A, B>): (self: Option<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>): (self: Option<A>) => Option<B>A, function (type parameter) B in <A, B extends A>(refinement: Refinement<A, B>): (self: Option<A>) => Option<B>B>): (self: Option<A>self: 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) A in <A, B extends A>(refinement: Refinement<A, B>): (self: Option<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>): (self: Option<A>) => Option<B>B>
<function (type parameter) A in <A>(predicate: Predicate<A>): <B extends A>(self: Option<B>) => Option<B>A>(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 <A>(predicate: Predicate<A>): <B extends A>(self: Option<B>) => Option<B>A>): <function (type parameter) B in <B extends A>(self: Option<B>): Option<B>B extends function (type parameter) A in <A>(predicate: Predicate<A>): <B extends A>(self: Option<B>) => Option<B>A>(self: Option<B>self: 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>(self: Option<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>(self: Option<B>): Option<B>B>
<function (type parameter) A in <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>A, function (type parameter) B in <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>B extends function (type parameter) A in <A, B extends A>(self: Option<A>, refinement: Refinement<A, B>): Option<B>A>(self: Option<A>self: 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) A in <A, B extends A>(self: Option<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: Option<A>, refinement: Refinement<A, B>): Option<B>A, function (type parameter) B in <A, B extends A>(self: Option<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: Option<A>, refinement: Refinement<A, B>): Option<B>B>
<function (type parameter) A in <A>(self: Option<A>, predicate: Predicate<A>): Option<A>A>(self: Option<A>self: 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) A in <A>(self: Option<A>, predicate: Predicate<A>): Option<A>A>, 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 <A>(self: Option<A>, predicate: Predicate<A>): Option<A>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) A in <A>(self: Option<A>, predicate: Predicate<A>): Option<A>A>
} = import dualdual(
2,
<function (type parameter) A in <A>(self: Option<A>, predicate: Predicate<A>): Option<A>A>(self: Option<A>self: 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) A in <A>(self: Option<A>, predicate: Predicate<A>): Option<A>A>, 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 <A>(self: Option<A>, predicate: Predicate<A>): Option<A>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) A in <A>(self: Option<A>, predicate: Predicate<A>): Option<A>A> =>
const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone(self: Option<A>self) ? 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() : predicate: Predicate<A>predicate(self: Option<A>(parameter) self: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Some<A>.value: Avalue) ? 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(self: Option<A>(parameter) self: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
self.Some<A>.value: Avalue) : 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()
)