diff --git a/packages/effect-lens/src/Lens.ts b/packages/effect-lens/src/Lens.ts index 3579b6a..5edc410 100644 --- a/packages/effect-lens/src/Lens.ts +++ b/packages/effect-lens/src/Lens.ts @@ -49,7 +49,7 @@ extends Pipeable.Class() implements Lens { abstract readonly resolve: Effect.Effect, ER, RR> abstract readonly changes: Stream.Stream - abstract readonly withLock: (self: Effect.Effect) => Effect.Effect + abstract readonly withLock: (self: Effect.Effect) => Effect.Effect get get() { return Effect.map(this.resolve, frame => frame.value) } @@ -82,7 +82,7 @@ export declare namespace LensLazyImpl { readonly get: Effect.Effect readonly changes: Stream.Stream readonly commit: (a: A) => Effect.Effect - readonly withLock: (self: Effect.Effect) => Effect.Effect + readonly withLock: (self: Effect.Effect) => Effect.Effect } } @@ -129,7 +129,10 @@ export declare namespace DerivedLensImpl { in out RSW = never, > { readonly resolve: (effect: Effect.Effect, ESR, RSR>) => Effect.Effect, ER, RR> - readonly transformStream: (stream: Stream.Stream) => Stream.Stream + readonly mapStream: (stream: Stream.Stream) => Stream.Stream + readonly withLock: ( + withLock: (self: Effect.Effect) => Effect.Effect + ) => (self: Effect.Effect) => Effect.Effect } } @@ -154,8 +157,8 @@ extends LensImpl { } get resolve() { return this.source.resolve(this.parent.resolve) } - get changes() { return this.source.transformStream(this.parent.changes) } - get withLock() { return this.parent.withLock } + get changes() { return this.source.mapStream(this.parent.changes) } + get withLock() { return this.source.withLock(this.parent.withLock) } } /** @@ -322,25 +325,26 @@ export const map: { ( self: Lens, get: (a: NoInfer) => B, - update: (a: NoInfer, b: B) => NoInfer, + set: (a: NoInfer, b: B) => NoInfer, ): Lens ( get: (a: NoInfer) => B, - update: (a: NoInfer, b: B) => NoInfer, + set: (a: NoInfer, b: B) => NoInfer, ): (self: Lens) => Lens } = Function.dual(3, ( self: Lens, get: (a: NoInfer) => B, - update: (a: NoInfer, b: B) => NoInfer, + set: (a: NoInfer, b: B) => NoInfer, ): Lens => derive(self, { resolve: parent => Effect.map( parent, frame => ({ value: get(frame.value), - commit: next => frame.commit(Effect.map(next, b => update(frame.value, b))), + commit: next => frame.commit(Effect.map(next, b => set(frame.value, b))), }), ), - transformStream: Stream.map(get), + mapStream: Stream.map(get), + withLock: identity, })) /** @@ -371,7 +375,8 @@ export const mapEffect: { }), ), ), - transformStream: Stream.mapEffect(get), + mapStream: Stream.mapEffect(get), + withLock: identity, })) /** @@ -456,7 +461,8 @@ export const mapStream: { f: (changes: Stream.Stream, NoInfer, NoInfer>) => Stream.Stream, NoInfer, NoInfer>, ): Lens => derive(self, { resolve: identity, - transformStream: f, + mapStream: f, + withLock: identity, })) @@ -478,7 +484,8 @@ export const mapErrorRead: { f: (error: NoInfer) => E2, ): Lens => derive(self, { resolve: Effect.mapError(f), - transformStream: Stream.mapError(f), + mapStream: Stream.mapError(f), + withLock: identity, })) /** @@ -506,7 +513,8 @@ export const mapErrorWrite: { value => Effect.mapError(frame.commit(Effect.succeed(value)), f), ), })), - transformStream: identity, + mapStream: identity, + withLock: identity, })) /** @@ -537,7 +545,8 @@ export const mapError: { ), }), ), - transformStream: Stream.mapError(f), + mapStream: Stream.mapError(f), + withLock: identity, })) /** @@ -561,7 +570,8 @@ export const catchAllRead: { parent, error => asLensImpl(f(error)).resolve as Effect.Effect, E2, R2>, ), - transformStream: Stream.catchAll(error => f(error).changes), + mapStream: Stream.catchAll(error => f(error).changes), + withLock: identity, } as DerivedLensImpl.Source)) /** @@ -588,7 +598,8 @@ export const catchAllWrite: { value => Effect.catchAll(frame.commit(Effect.succeed(value)), f), ), })), - transformStream: identity, + mapStream: identity, + withLock: identity, })) /** @@ -609,7 +620,8 @@ export const tapErrorRead: { f: (error: NoInfer) => Effect.Effect, ): Lens => derive(self, { resolve: Effect.tapError(f), - transformStream: Stream.tapError(f), + mapStream: Stream.tapError(f), + withLock: identity, })) /** @@ -637,7 +649,8 @@ export const tapErrorWrite: { value => Effect.tapError(frame.commit(Effect.succeed(value)), f), ), })), - transformStream: identity, + mapStream: identity, + withLock: identity, })) /** @@ -668,7 +681,8 @@ export const tapError: { ), }), ), - transformStream: Stream.tapError(f), + mapStream: Stream.tapError(f), + withLock: identity, })) @@ -694,7 +708,8 @@ export const provideContext: { commit: next => Effect.provide(frame.commit(Effect.provide(next, context)), context), }), ), - transformStream: Stream.provideSomeContext(context), + mapStream: Stream.provideSomeContext(context), + withLock: parentWithLock => self => Effect.provide(parentWithLock(Effect.provide(self, context)), context), })) /** @@ -725,7 +740,8 @@ export const provideService: { commit: next => Effect.provideService(frame.commit(Effect.provideService(next, tag, service)), tag, service), }), ), - transformStream: Stream.provideService(tag, service), + mapStream: Stream.provideService(tag, service), + withLock: parentWithLock => self => Effect.provideService(parentWithLock(Effect.provideService(self, tag, service)), tag, service), }))