(label?: string): <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
<A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<
A,
E,
R
>Runs an Effect with a console timer, starting the timer before execution and ending it after the Effect completes.
Example (Timing an effect)
import { Console, Effect } from "effect"
const program = Effect.gen(function*() {
yield* Console.withTime(
Effect.gen(function*() {
yield* Effect.sleep("1 second")
yield* Console.log("Operation completed")
}),
"my-operation"
)
})export const const withTime: ((
label?: string
) => <A, E, R>(
self: Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>) &
(<A, E, R>(
self: Effect.Effect<A, E, R>,
label?: string
) => Effect.Effect<A, E, R>)
Runs an Effect with a console timer, starting the timer before execution and ending it after the Effect completes.
Example (Timing an effect)
import { Console, Effect } from "effect"
const program = Effect.gen(function*() {
yield* Console.withTime(
Effect.gen(function*() {
yield* Effect.sleep("1 second")
yield* Console.log("Operation completed")
}),
"my-operation"
)
})
withTime = dual<(label?: string) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>, <A, E, R>(self: Effect.Effect<A, E, R>, label?: string) => Effect.Effect<A, E, R>>(isDataFirst: (args: IArguments) => boolean, body: <A, E, R>(self: Effect.Effect<A, E, R>, label?: string) => Effect.Effect<A, E, R>): ((label?: string) => <A, E, R>(self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>) & (<A, E, R>(self: Effect.Effect<A, E, R>, label?: string) => Effect.Effect<A, E, R>) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual<
(label: string | undefinedlabel?: string) => <function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>(self: Effect.Effect<A, E, R>(parameter) self: {
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;
}
self: 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<function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>) => 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<function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R>R>,
<function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>R>(self: Effect.Effect<A, E, R>(parameter) self: {
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;
}
self: 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<function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>R>, label: string | undefinedlabel?: string) => 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<function (type parameter) A in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>A, function (type parameter) E in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>E, function (type parameter) R in <A, E, R>(self: Effect.Effect<A, E, R>, label?: string): Effect.Effect<A, E, R>R>
>((args: IArgumentsargs) => import corecore.const isEffect: (
u: unknown
) => u is Effect.Effect<any, any, any>
isEffect(args: IArgumentsargs[0]), (self: Effect.Effect<A, E, R>(parameter) self: {
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;
}
self, label: string | undefinedlabel) =>
const consoleWith: <A, E, R>(
f: (console: Console) => Effect.Effect<A, E, R>
) => Effect.Effect<A, E, R>
Creates an Effect that provides access to the current console service and lets you perform operations with it within an Effect context.
Example (Accessing the current console service)
import { Console, Effect } from "effect"
const program = Console.consoleWith((console) =>
Effect.sync(() => {
console.log("Hello, world!")
console.error("This is an error message")
})
)
consoleWith((console: Console(parameter) console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console) =>
import effecteffect.const acquireUseRelease: <
Resource,
E,
R,
A,
E2,
R2,
E3,
R3
>(
acquire: Effect.Effect<Resource, E, R>,
use: (a: Resource) => Effect.Effect<A, E2, R2>,
release: (
a: Resource,
exit: Exit.Exit<A, E2>
) => Effect.Effect<void, E3, R3>
) => Effect.Effect<A, E | E2 | E3, R | R2 | R3>
acquireUseRelease(
import effecteffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect.Effect<A>
sync(() => {
console: Console(parameter) console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.Console.time(label?: string): voidtime(label: string | undefinedlabel)
}),
() => self: Effect.Effect<A, E, R>(parameter) self: {
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;
}
self,
() =>
import effecteffect.const sync: <A>(
thunk: LazyArg<A>
) => Effect.Effect<A>
sync(() => {
console: Console(parameter) console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.Console.timeEnd(label?: string): voidtimeEnd(label: string | undefinedlabel)
})
)
))