0.2.0 #5
@@ -1,4 +1,4 @@
|
||||
import { Array, Chunk, Effect, Function, identity, type Layer, Option, Pipeable, Predicate, Readable, Stream, type Context, type SubscriptionRef, type SynchronizedRef } from "effect"
|
||||
import { Array, Chunk, type Context, Effect, Function, identity, type Layer, type ManagedRuntime, Option, Pipeable, Predicate, Readable, type Runtime, Stream, type SubscriptionRef, type SynchronizedRef } from "effect"
|
||||
import type { NoSuchElementException } from "effect/Cause"
|
||||
import * as Subscribable from "./Subscribable.js"
|
||||
|
||||
@@ -270,7 +270,12 @@ export const mapStream: {
|
||||
}))
|
||||
|
||||
/**
|
||||
* Provides a single service to a `Lens`, removing it from both the read and write environments.
|
||||
* Provides the requirements of a `Lens`, removing them from both the read and write environments.
|
||||
*
|
||||
* Accepts the same provider forms as `Effect.provide`: one or more `Layer`s, a `Context`,
|
||||
* a `Runtime`, or a `ManagedRuntime`.
|
||||
*
|
||||
* Layer providers may add their construction errors to both the read and write error channels.
|
||||
*/
|
||||
export const provide: {
|
||||
<const Layers extends readonly [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
||||
@@ -288,6 +293,12 @@ export const provide: {
|
||||
<R2>(
|
||||
context: Context.Context<R2>,
|
||||
): <A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>) => Lens<A, ER, EW, Exclude<RR, R2>, Exclude<RW, R2>>
|
||||
<R2>(
|
||||
runtime: Runtime.Runtime<R2>,
|
||||
): <A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>) => Lens<A, ER, EW, Exclude<RR, R2>, Exclude<RW, R2>>
|
||||
<E2, R2>(
|
||||
managedRuntime: ManagedRuntime.ManagedRuntime<R2, E2>,
|
||||
): <A, ER, EW, RR, RW>(self: Lens<A, ER, EW, RR, RW>) => Lens<A, ER | E2, EW | E2, Exclude<RR, R2>, Exclude<RW, R2>>
|
||||
<A, ER, EW, RR, RW, const Layers extends readonly [Layer.Layer.Any, ...Array<Layer.Layer.Any>]>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
layers: Layers,
|
||||
@@ -306,24 +317,38 @@ export const provide: {
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
context: Context.Context<R2>,
|
||||
): Lens<A, ER, EW, Exclude<RR, R2>, Exclude<RW, R2>>
|
||||
} = Function.dual(2, <A, ER, EW, RR, RW>(
|
||||
<A, ER, EW, RR, RW, R2>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
provider: unknown,
|
||||
): Lens<A, any, any, any, any> => make({
|
||||
get get() { return Effect.provide(self.get, provider as any) },
|
||||
runtime: Runtime.Runtime<R2>,
|
||||
): Lens<A, ER, EW, Exclude<RR, R2>, Exclude<RW, R2>>
|
||||
<A, ER, EW, RR, RW, E2, R2>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
runtime: ManagedRuntime.ManagedRuntime<R2, E2>,
|
||||
): Lens<A, ER | E2, EW | E2, Exclude<RR, R2>, Exclude<RW, R2>>
|
||||
} = Function.dual(2, <A, ER, EW, RR, RW, ROut, E2, RIn>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
layer: Layer.Layer<ROut, E2, RIn>,
|
||||
): Lens<A, ER | E2, EW | E2, RIn | Exclude<RR, ROut>, RIn | Exclude<RW, ROut>> => make({
|
||||
get get() { return Effect.provide(self.get, layer) },
|
||||
get changes() {
|
||||
return Stream.unwrapScoped(
|
||||
Effect.map(
|
||||
Effect.provide(Effect.context<RR>(), provider as any),
|
||||
(context) => Stream.provideContext(self.changes as Stream.Stream<A, ER, RR>, context),
|
||||
Effect.provide(Effect.context<RR>(), layer),
|
||||
context => Stream.provideContext(self.changes, context),
|
||||
),
|
||||
)
|
||||
},
|
||||
modify: <B, E1 = never, R1 = never>(
|
||||
f: (a: A) => Effect.Effect<readonly [B, A], E1, R1>
|
||||
) => Effect.provide(self.modify(f), provider as any),
|
||||
) => Effect.provide(self.modify(f), layer),
|
||||
}))
|
||||
|
||||
/**
|
||||
* Provides a single service to a `Lens`, removing it from both the read and write environments.
|
||||
*
|
||||
* This is the `Lens` equivalent of `Effect.provideService`: use it when a lens requires one
|
||||
* `Context.Tag` and you already have the concrete service value.
|
||||
*/
|
||||
export const provideService: {
|
||||
<A, ER, EW, RR, RW, I, S>(
|
||||
self: Lens<A, ER, EW, RR, RW>,
|
||||
|
||||
Reference in New Issue
Block a user