<A, E>(self: Resource<A, E>): Effect.Effect<A, E>Retrieves the current value stored in this resource.
When to use
Use to read the value currently cached by a Resource.
Gotchas
If the resource currently stores a failed acquisition result, the returned effect fails with the stored error.
export const const get: <A, E>(
self: Resource<A, E>
) => Effect.Effect<A, E>
Retrieves the current value stored in this resource.
When to use
Use to read the value currently cached by a Resource.
Gotchas
If the resource currently stores a failed acquisition result, the returned
effect fails with the stored error.
get = <function (type parameter) A in <A, E>(self: Resource<A, E>): Effect.Effect<A, E>A, function (type parameter) E in <A, E>(self: Resource<A, E>): Effect.Effect<A, E>E>(self: Resource<A, E>(parameter) self: {
scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>;
acquire: Effect.Effect<A, E>;
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; <…;
}
self: interface Resource<in out A, in out E = never>A Resource is a value loaded into memory that can be refreshed manually or
automatically according to a schedule.
When to use
Use to model a scoped value whose latest acquisition result is kept available
for repeated reads and can be refreshed manually or on a schedule.
Resource<function (type parameter) A in <A, E>(self: Resource<A, E>): Effect.Effect<A, E>A, function (type parameter) E in <A, E>(self: Resource<A, E>): Effect.Effect<A, E>E>): 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>(self: Resource<A, E>): Effect.Effect<A, E>A, function (type parameter) E in <A, E>(self: Resource<A, E>): Effect.Effect<A, E>E> =>
import EffectEffect.const flatMap: {
<A, B, E1, R1>(
f: (a: A) => Effect<B, E1, R1>
): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E1 | E, R1 | R>
<A, E, R, B, E1, R1>(
self: Effect<A, E, R>,
f: (a: A) => Effect<B, E1, R1>
): Effect<B, E | E1, R | R1>
}
flatMap(import ScopedRefScopedRef.const get: <A>(
self: ScopedRef<A>
) => Effect.Effect<A>
Retrieves the current value of the scoped reference effectfully.
When to use
Use to read the value currently stored in a ScopedRef inside an Effect
workflow.
get(self: Resource<A, E>(parameter) self: {
scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>;
acquire: Effect.Effect<A, E>;
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; <…;
}
self.Resource<A, E>.scopedRef: ScopedRef.ScopedRef<Exit.Exit<A, E>>(property) Resource<A, E>.scopedRef: {
backing: Synchronized.SynchronizedRef<readonly [Scope.Closeable, 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; <…;
}
scopedRef), const identity: <A>(a: A) => AReturns its input argument unchanged.
When to use
Use to return a value unchanged where a function is required.
Example (Returning the same value)
import { identity } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(identity(5), 5)
identity)