<A, B>(f: (a: A) => B): (self: Option<A>) => Option<NonNullable<B>>
<A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>Combines flatMap with fromNullishOr: applies a function that
may return null/undefined to the value of a Some.
When to use
Use when you need to chain optional computations that use null or
undefined instead of Option, such as nested property access.
Details
None→NoneSome→ appliesf, then wraps via fromNullishOr
Example (Navigating optional properties)
import { Option } from "effect"
interface Employee {
company?: { address?: { street?: { name?: string } } }
}
const emp: Employee = {
company: { address: { street: { name: "high street" } } }
}
console.log(
Option.some(emp).pipe(
Option.flatMapNullishOr((e) => e.company?.address?.street?.name)
)
)
// Output: { _id: 'Option', _tag: 'Some', value: 'high street' }export const const flatMapNullishOr: {
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<NonNullable<B>>
<A, B>(self: Option<A>, f: (a: A) => B): Option<
NonNullable<B>
>
}
Combines
flatMap
with
fromNullishOr
: applies a function that
may return null/undefined to the value of a Some.
When to use
Use when you need to chain optional computations that use null or
undefined instead of Option, such as nested property access.
Details
None → None
Some → applies f, then wraps via
fromNullishOr
Example (Navigating optional properties)
import { Option } from "effect"
interface Employee {
company?: { address?: { street?: { name?: string } } }
}
const emp: Employee = {
company: { address: { street: { name: "high street" } } }
}
console.log(
Option.some(emp).pipe(
Option.flatMapNullishOr((e) => e.company?.address?.street?.name)
)
)
// Output: { _id: 'Option', _tag: 'Some', value: 'high street' }
flatMapNullishOr: {
<function (type parameter) A in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<NonNullable<B>>A, function (type parameter) B in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<NonNullable<B>>B>(f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<NonNullable<B>>A) => function (type parameter) B in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<NonNullable<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<NonNullable<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<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) B in <A, B>(f: (a: A) => B): (self: Option<A>) => Option<NonNullable<B>>B>>
<function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>A, function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<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<NonNullable<B>>A>, f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>A) => function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<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<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>B>>
} = import dualdual(
2,
<function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>A, function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<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<NonNullable<B>>A>, f: (a: A) => Bf: (a: Aa: function (type parameter) A in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>A) => function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<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<type NonNullable<T> = T & {}Exclude null and undefined from T
NonNullable<function (type parameter) B in <A, B>(self: Option<A>, f: (a: A) => B): Option<NonNullable<B>>B>> =>
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() : const fromNullishOr: <A>(
a: A
) => Option<NonNullable<A>>
Converts a nullable value (null or undefined) into an Option.
When to use
Use when you need JavaScript nullish values to become absence at an API
boundary while all other values, including falsy ones, remain present.
Details
null or undefined → None
- Any other value →
Some (typed as NonNullable<A>)
Example (Converting nullable values to an Option)
import { Option } from "effect"
console.log(Option.fromNullishOr(undefined))
// Output: { _id: 'Option', _tag: 'None' }
console.log(Option.fromNullishOr(null))
// Output: { _id: 'Option', _tag: 'None' }
console.log(Option.fromNullishOr(1))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
fromNullishOr(f: (a: A) => Bf(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))
)