Effect.Effect<Option.Option<string>, never, never>Identifier attached to the schedule entry that started the current run.
export const const currentScheduleId: Effect.Effect<
Option.Option<string>,
never,
never
>
const currentScheduleId: {
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;
}
Identifier attached to the schedule entry that started the current run.
currentScheduleId: import EffectEffect.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<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<string>, never, never> =
import EffectEffect.const serviceOption: <
ProcessScheduleContextTag,
ProcessScheduleContext
>(
key: Context.Key<
ProcessScheduleContextTag,
ProcessScheduleContext
>
) => Effect.Effect<
Option.Option<ProcessScheduleContext>,
never,
never
>
Optionally accesses a service from the environment.
When to use
Use to read an optional dependency from the current context without making
that dependency part of the effect's required environment.
Details
This function attempts to access a service from the environment. If the
service is available, it returns Some(service). If the service is not
available, it returns None. Unlike service, this function does not
require the service to be present in the environment.
Example (Accessing an optional service)
import { Context, Effect, Option } from "effect"
// Define a service key
const Logger = Context.Service<{
log: (msg: string) => void
}>("Logger")
// Use serviceOption to optionally access the logger
const program = Effect.gen(function*() {
const maybeLogger = yield* Effect.serviceOption(Logger)
if (Option.isSome(maybeLogger)) {
maybeLogger.value.log("Service is available")
} else {
console.log("Service not available")
}
})
serviceOption(class ProcessScheduleContextTagclass ProcessScheduleContextTag {
key: Identifier;
Service: {
id: Option.Option<string>;
};
of: (this: void, self: ProcessScheduleContext) => ProcessScheduleContext;
context: (self: ProcessScheduleContext) => Context.Context<ProcessScheduleContextTag>;
use: (f: (service: ProcessScheduleContext) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, ProcessScheduleContextTag | R>;
useSync: (f: (service: ProcessScheduleContext) => A) => Effect.Effect<A, never, ProcessScheduleContextTag>;
Identifier: Identifier;
stack: string | undefined;
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;
}
ProcessScheduleContextTag).Pipeable.pipe<Effect.Effect<Option.Option<ProcessScheduleContext>, never, never>, Effect.Effect<Option.Option<string>, never, never>>(this: Effect.Effect<Option.Option<ProcessScheduleContext>, never, never>, ab: (_: Effect.Effect<Option.Option<ProcessScheduleContext>, never, never>) => Effect.Effect<Option.Option<string>, never, never>): Effect.Effect<Option.Option<string>, never, never> (+21 overloads)pipe(
import EffectEffect.const map: <Option.Option<ProcessScheduleContext>, Option.Option<string>>(f: (a: Option.Option<ProcessScheduleContext>) => Option.Option<string>) => <E, R>(self: Effect.Effect<Option.Option<ProcessScheduleContext>, E, R>) => Effect.Effect<Option.Option<string>, E, R> (+1 overload)Transforms the value inside an effect by applying a function to it.
When to use
Use to transform an effect's success value with a function that returns a
plain value, producing a new effect without changing the original effect's
typed error or context requirements.
Details
map takes a function and applies it to the value contained within an
effect, creating a new effect with the transformed value.
It's important to note that effects are immutable, meaning that the original
effect is not modified. Instead, a new effect is returned with the updated
value.
Example (Choosing map syntax variants)
import { Effect, pipe } from "effect"
const myEffect = Effect.succeed(1)
const transformation = (n: number) => n + 1
const mappedWithPipe = pipe(myEffect, Effect.map(transformation))
const mappedWithDataFirst = Effect.map(myEffect, transformation)
const mappedWithMethod = myEffect.pipe(Effect.map(transformation))
Example (Adding a service charge)
import { Effect, pipe } from "effect"
const addServiceCharge = (amount: number) => amount + 1
const fetchTransactionAmount = Effect.promise(() => Promise.resolve(100))
const finalAmount = pipe(
fetchTransactionAmount,
Effect.map(addServiceCharge)
)
Effect.runPromise(finalAmount).then(console.log)
// Output: 101
map(
import OptionOption.const match: <Option.Option<string>, ProcessScheduleContext, Option.Option<string>>(options: {
readonly onNone: LazyArg<Option.Option<string>>;
readonly onSome: (a: ProcessScheduleContext) => Option.Option<string>;
}) => (self: Option.Option<ProcessScheduleContext>) => Option.Option<string> (+1 overload)
Pattern-matches on an Option, handling both None and Some cases.
When to use
Use when you need to handle both Some and None in one expression and
transform an Option into a plain value.
Details
- If
None, calls onNone and returns its result
- If
Some, calls onSome with the value and returns its result
- Supports the
dual API (data-last and data-first)
Example (Matching on an Option)
import { Option } from "effect"
const message = Option.match(Option.some(1), {
onNone: () => "Option is empty",
onSome: (value) => `Option has a value: ${value}`
})
console.log(message)
// Output: "Option has a value: 1"
match({
onNone: LazyArg<Option.Option<string>>onNone: () => import OptionOption.const none: <
string
>() => Option.Option<string>
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(),
onSome: (
a: ProcessScheduleContext
) => Option.Option<string>
onSome: (ctx: ProcessScheduleContext(parameter) ctx: {
id: Option.Option<string>;
}
ctx) => ctx: ProcessScheduleContext(parameter) ctx: {
id: Option.Option<string>;
}
ctx.ProcessScheduleContext.id: Option.Option<string>id,
}),
),
);