<T extends Iterable<Option.Option<X>>, X = any>(self: T): Array<
Option.Option.Value<ReadonlyArray.Infer<T>>
>Extracts all Some values from an iterable of Options, discarding Nones.
When to use
Use to collect only present values from an iterable of Option values while
discarding None values.
Example (Extracting Some values)
import { Array, Option } from "effect"
console.log(Array.getSomes([Option.some(1), Option.none(), Option.some(2)])) // [1, 2]export const const getSomes: <
T extends Iterable<Option.Option<X>>,
X = any
>(
self: T
) => Array<
Option.Option.Value<ReadonlyArray.Infer<T>>
>
Extracts all Some values from an iterable of Options, discarding Nones.
When to use
Use to collect only present values from an iterable of Option values while
discarding None values.
Example (Extracting Some values)
import { Array, Option } from "effect"
console.log(Array.getSomes([Option.some(1), Option.none(), Option.some(2)])) // [1, 2]
getSomes: <function (type parameter) T in <T extends Iterable<Option.Option<X>>, X = any>(self: T): Array<Option.Option.Value<ReadonlyArray.Infer<T>>>T extends interface Iterable<T, TReturn = any, TNext = any>Iterable<import OptionOption.type Option<A> = Option.None<A> | Option.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 <T extends Iterable<Option.Option<X>>, X = any>(self: T): Array<Option.Option.Value<ReadonlyArray.Infer<T>>>X>>, function (type parameter) X in <T extends Iterable<Option.Option<X>>, X = any>(self: T): Array<Option.Option.Value<ReadonlyArray.Infer<T>>>X = any>(
self: T extends Iterable<Option.Option<X>>self: function (type parameter) T in <T extends Iterable<Option.Option<X>>, X = any>(self: T): Array<Option.Option.Value<ReadonlyArray.Infer<T>>>T
) => interface Array<T>Array<import OptionOption.Option.type Option<A>.Value<T extends Option.Option<any>> = [T] extends [Option.Option<infer _A>] ? _A : neverExtracts the type of the value contained in an Option.
When to use
Use to infer the inner value type from an existing Option type.
Example (Extracting the value type)
import type { Option } from "effect"
declare const myOption: Option.Option<string>
// ┌─── string
// ▼
type MyType = Option.Option.Value<typeof myOption>
Value<ReadonlyArray.type ReadonlyArray.Infer<S extends Iterable<any>> = S extends readonly (infer A)[] ? A : S extends Iterable<infer A> ? A : neverInfers the element type of an iterable.
Example (Inferring an element type)
import type { Array } from "effect"
type StringArrayType = Array.ReadonlyArray.Infer<ReadonlyArray<string>>
// StringArrayType is string
Infer<function (type parameter) T in <T extends Iterable<Option.Option<X>>, X = any>(self: T): Array<Option.Option.Value<ReadonlyArray.Infer<T>>>T>>> = (self: anyself: any) => {
const const out: any[]out: interface Array<T>Array<any> = []
for (const const a: anya of self: anyself) {
if (import OptionOption.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(const a: anya)) {
const out: any[]out.Array<any>.push(...items: any[]): numberAppends new elements to the end of an array, and returns the new length of the array.
push(const a: Option.Some<unknown>const a: {
_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;
}
a.Some<unknown>.value: unknownvalue)
}
}
return const out: any[]out
}