<A>(self: Iterable<Option<A>>): Iterable<A>Retrieves the Some values from an Iterable of Options.
Example (Extracting Some values)
import { Iterable, Option } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Array.from(
Iterable.getSomes([Option.some(1), Option.none(), Option.some(2)])
),
[1, 2]
)export const const getSomes: <A>(
self: Iterable<Option<A>>
) => Iterable<A>
Retrieves the Some values from an Iterable of Options.
Example (Extracting Some values)
import { Iterable, Option } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
Array.from(
Iterable.getSomes([Option.some(1), Option.none(), Option.some(2)])
),
[1, 2]
)
getSomes = <function (type parameter) A in <A>(self: Iterable<Option<A>>): Iterable<A>A>(self: Iterable<Option<A>>self: interface Iterable<T, TReturn = any, TNext = any>Iterable<type Option<A> = O.None<A> | O.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: Iterable<Option<A>>): Iterable<A>A>>): interface Iterable<T, TReturn = any, TNext = any>Iterable<function (type parameter) A in <A>(self: Iterable<Option<A>>): Iterable<A>A> => {
return {
[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]() {
const const iterator: Iterator<
Option<A>,
any,
any
>
iterator = self: Iterable<Option<A>>self[var Symbol: SymbolConstructorSymbol.SymbolConstructor.iterator: typeof Symbol.iteratorA method that returns the default iterator for an object. Called by the semantics of the
for-of statement.
iterator]()
return {
Iterator<A, any, any>.next(...[value]: [] | [any]): IteratorResult<A, any>next() {
let let result: IteratorResult<Option<A>, any>result = const iterator: Iterator<
Option<A>,
any,
any
>
iterator.Iterator<Option<A>, any, any>.next(...[value]: [] | [any]): IteratorResult<Option<A>, any>next()
while (!let result: IteratorResult<Option<A>, any>result.done?: boolean | undefineddone) {
if (import OO.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 result: IteratorYieldResult<Option<A>>result.IteratorYieldResult<Option<A>>.value: Option<A>value)) {
return { IteratorYieldResult<TYield>.done?: false | undefineddone: false, IteratorYieldResult<A>.value: Avalue: let result: IteratorYieldResult<Option<A>>result.IteratorYieldResult<Option<A>>.value: O.Some<A>(property) IteratorYieldResult<Option<A>>.value: {
_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;
}
value.Some<A>.value: Avalue }
}
let result: IteratorResult<Option<A>, any>result = const iterator: Iterator<
Option<A>,
any,
any
>
iterator.Iterator<Option<A>, any, any>.next(...[value]: [] | [any]): IteratorResult<Option<A>, any>next()
}
return { IteratorReturnResult<TReturn>.done: truedone: true, IteratorReturnResult<any>.value: anyvalue: var undefinedundefined }
}
}
}
}
}