<T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [
C
] extends [Iterable<Option<infer A>>]
? Option<A>
: neverReturns the first Some found in an iterable of Options, or None if
all are None.
When to use
Use when you need the first available Some value from a priority list.
Details
- Short-circuits on the first
Some - Returns
Noneonly when every element isNone
Example (Finding the first Some)
import { Option } from "effect"
console.log(Option.firstSomeOf([
Option.none(),
Option.some(1),
Option.some(2)
]))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }export const const firstSomeOf: <
T,
C extends Iterable<Option<T>> = Iterable<
Option<T>
>
>(
collection: C
) => [C] extends [Iterable<Option<infer A>>]
? Option<A>
: never
Returns the first Some found in an iterable of Options, or None if
all are None.
When to use
Use when you need the first available Some value from a priority list.
Details
- Short-circuits on the first
Some
- Returns
None only when every element is None
Example (Finding the first Some)
import { Option } from "effect"
console.log(Option.firstSomeOf([
Option.none(),
Option.some(1),
Option.some(2)
]))
// Output: { _id: 'Option', _tag: 'Some', value: 1 }
firstSomeOf = <function (type parameter) T in <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [C] extends [Iterable<Option<infer A>>] ? Option<A> : neverT, function (type parameter) C in <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [C] extends [Iterable<Option<infer A>>] ? Option<A> : neverC extends interface Iterable<T, TReturn = any, TNext = any>Iterable<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) T in <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [C] extends [Iterable<Option<infer A>>] ? Option<A> : neverT>> = interface Iterable<T, TReturn = any, TNext = any>Iterable<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) T in <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [C] extends [Iterable<Option<infer A>>] ? Option<A> : neverT>>>(
collection: C extends Iterable<Option<T>> = Iterable<Option<T>>collection: function (type parameter) C in <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [C] extends [Iterable<Option<infer A>>] ? Option<A> : neverC
): [function (type parameter) C in <T, C extends Iterable<Option<T>> = Iterable<Option<T>>>(collection: C): [C] extends [Iterable<Option<infer A>>] ? Option<A> : neverC] extends [interface Iterable<T, TReturn = any, TNext = any>Iterable<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<infer function (type parameter) AA>>] ? 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) AA> : never => {
let let out: Option<unknown>out: 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<unknown> = 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()
for (let out: Option<unknown>out of collection: C extends Iterable<Option<T>> = Iterable<Option<T>>collection) {
if (const isSome: <A>(
self: Option<A>
) => self is Some<A>
Checks whether an Option contains a value (Some).
When to use
Use when you need to branch on a present Option before accessing .value.
Details
- Acts as a type guard, narrowing to
Some<A>
Example (Checking for Some)
import { Option } from "effect"
console.log(Option.isSome(Option.some(1)))
// Output: true
console.log(Option.isSome(Option.none()))
// Output: false
isSome(let out: Option<unknown>out)) {
return let out: Option<unknown>let out: {
_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;
}
out as any
}
}
return let out: Option<unknown>out as any
}