<A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>
<A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>Transforms and filters an Option using a Filter callback.
When to use
Use to transform an Option's present value and discard it when the Filter
fails.
Details
The callback returns a Result: Result.succeed keeps and transforms the
value, while Result.fail discards it.
Example (Filtering and transforming)
import { Option, Result } from "effect"
console.log(Option.filterMap(
Option.some(2),
(n) => (n % 2 === 0 ? Result.succeed(`Even: ${n}`) : Result.failVoid)
))
// Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }export const const filterMap: {
<A, B, X>(f: Filter.Filter<A, B, X>): (
self: Option<A>
) => Option<B>
<A, B, X>(
self: Option<A>,
f: Filter.Filter<A, B, X>
): Option<B>
}
Transforms and filters an Option using a Filter callback.
When to use
Use to transform an Option's present value and discard it when the Filter
fails.
Details
The callback returns a Result: Result.succeed keeps and transforms the
value, while Result.fail discards it.
Example (Filtering and transforming)
import { Option, Result } from "effect"
console.log(Option.filterMap(
Option.some(2),
(n) => (n % 2 === 0 ? Result.succeed(`Even: ${n}`) : Result.failVoid)
))
// Output: { _id: 'Option', _tag: 'Some', value: 'Even: 2' }
filterMap: {
<function (type parameter) A in <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>A, function (type parameter) B in <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>B, function (type parameter) X in <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>X>(f: Filter.Filter<A, B, X>f: import FilterFilter.type Filter.Filter = /*unresolved*/ anyFilter<function (type parameter) A in <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>A, function (type parameter) B in <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>B, function (type parameter) X in <A, B, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>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, B, X>(f: Filter.Filter<A, B, X>): (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, X>(f: Filter.Filter<A, B, X>): (self: Option<A>) => Option<B>B>
<function (type parameter) A in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>A, function (type parameter) B in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>B, function (type parameter) X in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>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, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>A>, f: Filter.Filter<A, B, X>f: import FilterFilter.type Filter.Filter = /*unresolved*/ anyFilter<function (type parameter) A in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>A, function (type parameter) B in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>B, function (type parameter) X in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>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) B in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>B>
} = import dualdual(2, <function (type parameter) A in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>A, function (type parameter) B in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>B, function (type parameter) X in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>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, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>A>, f: Filter.Filter<A, B, X>f: import FilterFilter.type Filter.Filter = /*unresolved*/ anyFilter<function (type parameter) A in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>A, function (type parameter) B in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>B, function (type parameter) X in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>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) B in <A, B, X>(self: Option<A>, f: Filter.Filter<A, B, X>): Option<B>B> => {
if (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)) {
return 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 const next: Result<B, X>next = f: Filter.Filter<A, B, X>f(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)
return import resultresult.const isSuccess: <A, E>(
result: Result.Result<A, E>
) => result is Result.Success<A, E>
isSuccess(const next: Result<B, X>next) ? 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 next: Success<B, X>const next: {
_tag: "Success";
_op: "Success";
success: 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;
}
next.Success<unknown, unknown>.success: unknownsuccess) : 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()
})