<
Arg extends Option<unknown> | LazyArg<unknown>,
E = Cause.NoSuchElementError
>(
arg: Arg,
...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []
): [Arg] extends [Option<infer A>]
? Effect<A, E>
: [Arg] extends [LazyArg<infer E>]
? <A>(option: Option<A>) => Effect<A, E>
: neverConverts an Option into an Effect.
When to use
Use when absence should become a typed NoSuchElementError in the effect error
channel.
Details
Option.some becomes a successful effect with the contained value, while
Option.none becomes a failed effect. By default the failure is a
NoSuchElementError, but you can provide an onNone callback to customize
the error value.
Example (Converting an Option into an Effect)
import { Effect, Option } from "effect"
const some = Option.some(42)
const none = Option.none()
const effect1 = Effect.fromOption(some)
const effect2 = Effect.fromOption(none)
const effect3 = Effect.fromOption(none, () => new Error("missing"))
Effect.runPromise(effect1).then(console.log) // 42
Effect.runPromiseExit(effect2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: { _id: 'NoSuchElementError' } } }export const const fromOption: <
Arg extends Option<unknown> | LazyArg<unknown>,
E = Cause.NoSuchElementError
>(
arg: Arg,
...rest: [Arg] extends [Option<unknown>]
? [onNone?: LazyArg<E>]
: []
) => [Arg] extends [Option<infer A>]
? Effect<A, E>
: [Arg] extends [LazyArg<infer E>]
? <A>(option: Option<A>) => Effect<A, E>
: never
Converts an Option into an Effect.
When to use
Use when absence should become a typed NoSuchElementError in the effect error
channel.
Details
Option.some becomes a successful effect with the contained value, while
Option.none becomes a failed effect. By default the failure is a
NoSuchElementError, but you can provide an onNone callback to customize
the error value.
Example (Converting an Option into an Effect)
import { Effect, Option } from "effect"
const some = Option.some(42)
const none = Option.none()
const effect1 = Effect.fromOption(some)
const effect2 = Effect.fromOption(none)
const effect3 = Effect.fromOption(none, () => new Error("missing"))
Effect.runPromise(effect1).then(console.log) // 42
Effect.runPromiseExit(effect2).then(console.log)
// { _id: 'Exit', _tag: 'Failure', cause: { _id: 'Cause', _tag: 'Fail', failure: { _id: 'NoSuchElementError' } } }
fromOption: <function (type parameter) Arg in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverArg extends 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> | type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<unknown>, function (type parameter) E in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverE = import CauseCause.type Cause.NoSuchElementError = /*unresolved*/ anyNoSuchElementError>(
arg: Arg extends Option<unknown> | LazyArg<unknown>arg: function (type parameter) Arg in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverArg,
...rest: [Arg] extends [Option<unknown>]
? [onNone?: LazyArg<E>]
: []
rest: [function (type parameter) Arg in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverArg] extends [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>] ? [LazyArg<E> | undefinedonNone?: type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<function (type parameter) E in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverE>] : []
) => [function (type parameter) Arg in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverArg] extends [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>] ? interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) AA, function (type parameter) E in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverE>
: [function (type parameter) Arg in <Arg extends Option<unknown> | LazyArg<unknown>, E = Cause.NoSuchElementError>(arg: Arg, ...rest: [Arg] extends [Option<unknown>] ? [onNone?: LazyArg<E>] : []): [Arg] extends [Option<infer A>] ? Effect<A, E> : [Arg] extends [LazyArg<infer E>] ? <A>(option: Option<A>) => Effect<A, E> : neverArg] extends [type LazyArg<A> = () => AA zero-argument function that produces a value when invoked.
When to use
Use to type a lazy value provider that should not run until called.
Example (Creating a lazy argument)
import { Function } from "effect"
const constNull: Function.LazyArg<null> = Function.constant(null)
LazyArg<infer function (type parameter) EE>] ? <function (type parameter) A in <A>(option: Option<A>): Effect<A, E>A>(option: Option<A>option: 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>(option: Option<A>): Effect<A, E>A>) => interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<function (type parameter) A in <A>(option: Option<A>): Effect<A, E>A, function (type parameter) EE>
: never = import internalinternal.const fromOption: <
Arg extends
| Option.Option<unknown>
| LazyArg<unknown>,
E = Cause.NoSuchElementError
>(
arg: Arg,
...rest: [Arg] extends [Option.Option<unknown>]
? [onNone?: LazyArg<E>]
: []
) => [Arg] extends [Option.Option<infer A>]
? Effect.Effect<A, E>
: [Arg] extends [LazyArg<infer E>]
? <A>(
option: Option.Option<A>
) => Effect.Effect<A, E>
: never
fromOption