<A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>
<A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>Runs a side-effecting Option-returning function on the value of a Some,
returning the original Option if the function returns Some, or None
if it returns None.
When to use
Use to validate an Option's present value without transforming it, such as
adding a side-condition check in a pipeline.
Details
None→NoneSome→ callsf(value); if result isSome, returns originalself; ifNone, returnsNone
Example (Validating without transforming)
import { Option } from "effect"
const getInteger = (n: number) =>
Number.isInteger(n) ? Option.some(n) : Option.none()
console.log(Option.tap(Option.some(1), getInteger))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
console.log(Option.tap(Option.some(1.14), getInteger))
// Output: { _id: 'Option', _tag: 'None' }export const const tap: {
<A, X>(f: (a: A) => Option<X>): (
self: Option<A>
) => Option<A>
<A, X>(
self: Option<A>,
f: (a: A) => Option<X>
): Option<A>
}
Runs a side-effecting Option-returning function on the value of a Some,
returning the original Option if the function returns Some, or None
if it returns None.
When to use
Use to validate an Option's present value without transforming it, such as
adding a side-condition check in a pipeline.
Details
None → None
Some → calls f(value); if result is Some, returns original self; if None, returns None
Example (Validating without transforming)
import { Option } from "effect"
const getInteger = (n: number) =>
Number.isInteger(n) ? Option.some(n) : Option.none()
console.log(Option.tap(Option.some(1), getInteger))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
console.log(Option.tap(Option.some(1.14), getInteger))
// Output: { _id: 'Option', _tag: 'None' }
tap: {
<function (type parameter) A in <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>A, function (type parameter) X in <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>X>(f: (a: A) => Option<X>f: (a: Aa: function (type parameter) A in <A, X>(f: (a: A) => Option<X>): (self: 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) X in <A, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>X>): (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, X>(f: (a: A) => Option<X>): (self: 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, X>(f: (a: A) => Option<X>): (self: Option<A>) => Option<A>A>
<function (type parameter) A in <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>A, function (type parameter) X in <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>X>(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, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>A>, f: (a: A) => Option<X>f: (a: Aa: function (type parameter) A in <A, X>(self: Option<A>, f: (a: A) => Option<X>): 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) X in <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>X>): 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, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>A>
} = import dualdual(2, <function (type parameter) A in <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>A, function (type parameter) X in <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>X>(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, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>A>, f: (a: A) => Option<X>f: (a: Aa: function (type parameter) A in <A, X>(self: Option<A>, f: (a: A) => Option<X>): 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) X in <A, X>(self: Option<A>, f: (a: A) => Option<X>): Option<A>X>): 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, X>(self: Option<A>, f: (a: A) => Option<X>): 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(self: Option<A>self, (a: Aa) => const map: {
<A, B>(f: (a: A) => B): (
self: Option<A>
) => Option<B>
<A, B>(
self: Option<A>,
f: (a: A) => B
): Option<B>
}
map(f: (a: A) => Option<X>f(a: Aa), () => a: Aa)))