<A>(self: Option<Option<A>>): Option<A>Flattens a nested Option<Option<A>> into Option<A>.
When to use
Use when you need to remove one layer of nested Option.
Details
Some(Some(value))→Some(value)Some(None)→NoneNone→None
Example (Flattening nested Options)
import { Option } from "effect"
console.log(Option.flatten(Option.some(Option.some("value"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'value' }
console.log(Option.flatten(Option.some(Option.none())))
// Output: { _id: 'Option', _tag: 'None' }export const const flatten: <A>(
self: Option<Option<A>>
) => Option<A>
Flattens a nested Option<Option<A>> into Option<A>.
When to use
Use when you need to remove one layer of nested Option.
Details
Some(Some(value)) → Some(value)
Some(None) → None
None → None
Example (Flattening nested Options)
import { Option } from "effect"
console.log(Option.flatten(Option.some(Option.some("value"))))
// Output: { _id: 'Option', _tag: 'Some', value: 'value' }
console.log(Option.flatten(Option.some(Option.none())))
// Output: { _id: 'Option', _tag: 'None' }
flatten: <function (type parameter) A in <A>(self: Option<Option<A>>): Option<A>A>(self: Option<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<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<Option<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<Option<A>>): Option<A>A> = 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(import identityidentity)