<A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>
<B>(f: Option<B>): <A>(self: Option<A>) => Option<B>
<A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>
<B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>
<A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>
<A, B>(self: Option<A>, f: Option<B>): Option<B>
<A, B>(self: Option<A>, f: (a: A) => B): Option<B>
<A, B>(self: Option<A>, f: NotFunction<B>): Option<B>Chains a second computation onto an Option. The second value can be a
plain value, an Option, or a function returning either.
When to use
Use when you need to chain an Option with a next step that may be another
Option, a plain value, or a function.
Details
- If
selfisNone, returnsNoneimmediately - If
fis a function, calls it with theSomevalue - If
freturns anOption, returns it as-is; if a plain value, wraps inSome - If
fis not a function, uses it directly (same wrapping rules)
Example (Chaining with andThen)
import { Option } from "effect"
// Chain with a function returning Option
console.log(Option.andThen(Option.some(5), (x) => Option.some(x * 2)))
// Output: { _id: 'Option', _tag: 'Some', value: 10 }
// Chain with a static value
console.log(Option.andThen(Option.some(5), "hello"))
// Output: { _id: 'Option', _tag: 'Some', value: "hello" }
// Chain with None - skips
console.log(Option.andThen(Option.none(), (x) => Option.some(x * 2)))
// Output: { _id: 'Option', _tag: 'None' }export const const andThen: {
<A, B>(f: (a: A) => Option<B>): (
self: Option<A>
) => Option<B>
<B>(f: Option<B>): <A>(
self: Option<A>
) => Option<B>
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<B>
<B>(f: NotFunction<B>): <A>(
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => Option<B>
): Option<B>
<A, B>(self: Option<A>, f: Option<B>): Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => B
): Option<B>
<A, B>(
self: Option<A>,
f: NotFunction<B>
): Option<B>
}
Chains a second computation onto an Option. The second value can be a
plain value, an Option, or a function returning either.
When to use
Use when you need to chain an Option with a next step that may be another
Option, a plain value, or a function.
Details
- If
self is None, returns None immediately
- If
f is a function, calls it with the Some value
- If
f returns an Option, returns it as-is; if a plain value, wraps in Some
- If
f is not a function, uses it directly (same wrapping rules)
Example (Chaining with andThen)
import { Option } from "effect"
// Chain with a function returning Option
console.log(Option.andThen(Option.some(5), (x) => Option.some(x * 2)))
// Output: { _id: 'Option', _tag: 'Some', value: 10 }
// Chain with a static value
console.log(Option.andThen(Option.some(5), "hello"))
// Output: { _id: 'Option', _tag: 'Some', value: "hello" }
// Chain with None - skips
console.log(Option.andThen(Option.none(), (x) => Option.some(x * 2)))
// Output: { _id: 'Option', _tag: 'None' }
andThen: {
<function (type parameter) A in <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>A, function (type parameter) B in <A, B>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>B>(f: (a: A) => Option<B>f: (a: Aa: function (type parameter) A in <A, B>(f: (a: A) => Option<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>(f: (a: A) => Option<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>(f: (a: A) => Option<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>(f: (a: A) => Option<B>): (self: Option<A>) => Option<B>B>
<function (type parameter) B in <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>B>(f: Option<B>f: 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>(f: Option<B>): <A>(self: Option<A>) => Option<B>B>): <function (type parameter) A in <A>(self: Option<A>): 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>(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 <B>(f: Option<B>): <A>(self: Option<A>) => Option<B>B>
<function (type parameter) A in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>A, function (type parameter) B in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>B>(f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<B>A) => function (type parameter) B in <A, B>(f: (a: 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>(f: (a: 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>(f: (a: A) => B): (self: Option<A>) => Option<B>B>
<function (type parameter) B in <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>B>(f: NotFunction<B>f: type NotFunction<T> = T extends Function ? never : TExcludes function types from a union, keeping only non-function members.
When to use
Use to filter out callable types from a union.
Details
Returns never if the entire union consists of function types.
Example (Filtering out functions)
import type { Types } from "effect"
type Result = Types.NotFunction<string | (() => void) | number>
// string | number
NotFunction<function (type parameter) B in <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>B>): <function (type parameter) A in <A>(self: Option<A>): 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>(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 <B>(f: NotFunction<B>): <A>(self: Option<A>) => Option<B>B>
<function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>A, function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => Option<B>): 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>(self: Option<A>, f: (a: A) => Option<B>): Option<B>A>, f: (a: A) => Option<B>f: (a: Aa: function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => Option<B>): 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>(self: Option<A>, f: (a: A) => 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 <A, B>(self: Option<A>, f: (a: A) => Option<B>): Option<B>B>
<function (type parameter) A in <A, B>(self: Option<A>, f: Option<B>): Option<B>A, function (type parameter) B in <A, B>(self: Option<A>, f: Option<B>): 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>(self: Option<A>, f: Option<B>): Option<B>A>, f: Option<B>f: 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>(self: Option<A>, f: 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 <A, B>(self: Option<A>, f: Option<B>): Option<B>B>
<function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => B): Option<B>A, function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): 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>(self: Option<A>, f: (a: A) => B): Option<B>A>, f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => B): Option<B>A) => function (type parameter) B in <A, B>(self: Option<A>, f: (a: 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>(self: Option<A>, f: (a: A) => B): Option<B>B>
<function (type parameter) A in <A, B>(self: Option<A>, f: NotFunction<B>): Option<B>A, function (type parameter) B in <A, B>(self: Option<A>, f: NotFunction<B>): 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>(self: Option<A>, f: NotFunction<B>): Option<B>A>, f: NotFunction<B>f: type NotFunction<T> = T extends Function ? never : TExcludes function types from a union, keeping only non-function members.
When to use
Use to filter out callable types from a union.
Details
Returns never if the entire union consists of function types.
Example (Filtering out functions)
import type { Types } from "effect"
type Result = Types.NotFunction<string | (() => void) | number>
// string | number
NotFunction<function (type parameter) B in <A, B>(self: Option<A>, f: NotFunction<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>(self: Option<A>, f: NotFunction<B>): Option<B>B>
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B>A, function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): 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>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B>A>, f: (a: A) => Option<B> | Option<B>f: (a: Aa: function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): 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>(self: Option<A>, f: (a: A) => Option<B> | 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 <A, B>(self: Option<A>, f: (a: A) => Option<B> | 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 <A, B>(self: Option<A>, f: (a: A) => Option<B> | Option<B>): Option<B>B> =>
const flatMap: {
<A, B>(f: (a: A) => Option<B>): (
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => Option<B>
): Option<B>
}
flatMap(self: Option<A>self, (a: Aa) => {
const const b: Option<B>b = function isFunction(input: unknown): input is FunctionChecks whether a value is a function.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
callable function.
Details
Uses typeof input === "function".
Example (Guarding functions)
import { Predicate } from "effect"
const data: unknown = () => 1
if (Predicate.isFunction(data)) {
console.log(data())
}
isFunction(f: (a: A) => Option<B> | Option<B>f) ? f: (a: A) => Option<B> | Option<B>f(a: Aa) : f: (a: A) => Option<B> | Option<B>f
return const isOption: (
input: unknown
) => input is Option<unknown>
Determines whether the given value is an Option.
When to use
Use to validate unknown values at runtime boundaries, such as type-narrowing
in union types.
Details
- Returns
true for both Some and None instances
- Acts as a type guard, narrowing the input to
Option<unknown>
Example (Checking if a value is an Option)
import { Option } from "effect"
console.log(Option.isOption(Option.some(1)))
// Output: true
console.log(Option.isOption(Option.none()))
// Output: true
console.log(Option.isOption({}))
// Output: false
isOption(const b: Option<B>b) ? const b: None<B> | Some<B>b : 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(const b: neverb)
})
)