diff --git a/packages/effect-lens/src/Lens.ts b/packages/effect-lens/src/Lens.ts index 8b28408..4d9063c 100644 --- a/packages/effect-lens/src/Lens.ts +++ b/packages/effect-lens/src/Lens.ts @@ -58,15 +58,6 @@ export interface LensStep< export const isLensStep = (u: unknown): u is LensStep => Predicate.hasProperty(u, LensStepTypeId) -// export const asLensWithInternals = ( -// lens: Lens -// ): LensWithInternals => { -// if (!isLensWithInternals(lens)) -// throw new Error("Not a 'LensWithInternals'.") -// return lens as LensWithInternals -// } - - export const LensImplTypeId: unique symbol = Symbol.for("@effect-fc/Lens/LensImpl") export type LensImplTypeId = typeof LensImplTypeId @@ -92,7 +83,7 @@ extends Pipeable.Class() implements Lens { abstract readonly sourceGet: Effect.Effect abstract readonly sourceChanges: Stream.Stream - abstract readonly sourceCommit: (b: B) => Effect.Effect + abstract sourceCommit(b: B): Effect.Effect abstract readonly withLock: (self: Effect.Effect) => Effect.Effect private get access(): Effect.Effect, ER, RR> { @@ -134,40 +125,25 @@ extends Pipeable.Class() implements Lens { } } -// export declare namespace LensImpl { -// export interface Source { -// readonly get: Effect.Effect, -// readonly changes: Stream.Stream, -// readonly update: (a: A) => Effect.Effect, -// readonly withLock: (self: Effect.Effect) => Effect.Effect, -// } -// } -// export class LensImpl -// extends Pipeable.Class() implements LensWithInternals { -// readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId -// readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId -// readonly [LensTypeId]: LensTypeId = LensTypeId -// readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId -// readonly get: Effect.Effect -// readonly changes: Stream.Stream -// readonly update: (a: A) => Effect.Effect -// readonly withLock: (self: Effect.Effect) => Effect.Effect -// constructor( -// source: LensImpl.Source -// ) { -// super() +export abstract class LensLazyImpl< + in out A, + in out B, + in out ER = never, + in out ESR = never, + in out EW = never, + in out ESW = never, + in out RR = never, + in out RSR = never, + in out RW = never, + in out RSW = never, +> +extends Pipeable.Class() implements Lens { -// this.get = source.get -// this.changes = source.changes -// this.update = source.update -// this.withLock = source.withLock -// } +} -// modifyEffect = modifyEffect -// } /** * Creates a `Lens` by supplying how to read the current value, observe changes, and apply transformations. @@ -176,28 +152,6 @@ export const make = ( source: LensImpl.Source ): Lens => new LensImpl(source) - -// export class LensLazyImpl -// extends Pipeable.Class() implements LensWithInternals { -// readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId -// readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId -// readonly [LensTypeId]: LensTypeId = LensTypeId -// readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId - -// constructor( -// readonly source: LensImpl.Source -// ) { -// super() -// } - -// get get() { return this.source.get } -// get changes() { return this.source.changes } -// get update() { return this.source.update } -// get withLock() { return this.source.withLock } - -// modifyEffect = modifyEffect -// } - /** * Creates a `Lens` by supplying how to read the current value, observe changes, and apply transformations. */ @@ -215,12 +169,7 @@ export declare namespace SynchronizedRefLensImpl { } export class SynchronizedRefLensImpl -extends Pipeable.Class() implements LensWithInternals { - readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId - readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId - readonly [LensTypeId]: LensTypeId = LensTypeId - readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId - +extends LensImpl { readonly ref: SynchronizedRefLensImpl.SynchronizedRefWithInternals constructor( @@ -230,12 +179,10 @@ extends Pipeable.Class() implements LensWithInternals } - get get() { return this.ref.get } - get changes() { return Stream.unwrap(Effect.map(this.ref.get, Stream.make)) } - update(a: A) { return Ref.set(this.ref.ref, a) } + get sourceGet() { return this.ref.get } + get sourceChanges() { return Stream.unwrap(Effect.map(this.ref.get, Stream.make)) } + sourceCommit(a: A) { return Ref.set(this.ref.ref, a) } get withLock() { return this.ref.withLock } - - modifyEffect = modifyEffect } /** @@ -259,12 +206,7 @@ export declare namespace SubscriptionRefLensImpl { } export class SubscriptionRefLensImpl -extends Pipeable.Class() implements LensWithInternals { - readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId - readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId - readonly [LensTypeId]: LensTypeId = LensTypeId - readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId - +extends LensImpl { readonly ref: SubscriptionRefLensImpl.SubscriptionRefWithInternals constructor( @@ -274,17 +216,15 @@ extends Pipeable.Class() implements LensWithInternals } - get get() { return this.ref.get } - get changes() { return this.ref.changes } - update(a: A) { + get sourceGet() { return this.ref.get } + get sourceChanges() { return this.ref.changes } + sourceCommit(a: A) { return Effect.zipLeft( Ref.set(this.ref.ref, a), PubSub.publish(this.ref.pubsub, a), ) } get withLock() { return this.ref.semaphore.withPermits(1) } - - modifyEffect = modifyEffect } /**