0.2.0 #5
@@ -58,15 +58,6 @@ export interface LensStep<
|
||||
export const isLensStep = (u: unknown): u is LensStep<unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown, unknown> => Predicate.hasProperty(u, LensStepTypeId)
|
||||
|
||||
|
||||
// export const asLensWithInternals = <A, ER, EW, RR, RW>(
|
||||
// lens: Lens<A, ER, EW, RR, RW>
|
||||
// ): LensWithInternals<A, ER, EW, RR, RW> => {
|
||||
// if (!isLensWithInternals(lens))
|
||||
// throw new Error("Not a 'LensWithInternals'.")
|
||||
// return lens as LensWithInternals<A, ER, EW, RR, RW>
|
||||
// }
|
||||
|
||||
|
||||
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<A, ER, EW, RR, RW> {
|
||||
|
||||
abstract readonly sourceGet: Effect.Effect<B, ESR, RSR>
|
||||
abstract readonly sourceChanges: Stream.Stream<B, ESR, RSR>
|
||||
abstract readonly sourceCommit: (b: B) => Effect.Effect<void, ESW, RSW>
|
||||
abstract sourceCommit(b: B): Effect.Effect<void, ESW, RSW>
|
||||
abstract readonly withLock: <A1, E1, R1>(self: Effect.Effect<A1, E1, R1>) => Effect.Effect<A1, EW | E1, RW | R1>
|
||||
|
||||
private get access(): Effect.Effect<LensFrame<A, EW, RW>, ER, RR> {
|
||||
@@ -134,40 +125,25 @@ extends Pipeable.Class() implements Lens<A, ER, EW, RR, RW> {
|
||||
}
|
||||
}
|
||||
|
||||
// export declare namespace LensImpl {
|
||||
// export interface Source<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never> {
|
||||
// readonly get: Effect.Effect<A, ER, RR>,
|
||||
// readonly changes: Stream.Stream<A, ER, RR>,
|
||||
// readonly update: (a: A) => Effect.Effect<void, EW, RW>,
|
||||
// readonly withLock: <A1, E1, R1>(self: Effect.Effect<A1, E1, R1>) => Effect.Effect<A1, EW | E1, RW | R1>,
|
||||
// }
|
||||
// }
|
||||
|
||||
// export class LensImpl<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never>
|
||||
// extends Pipeable.Class() implements LensWithInternals<A, ER, EW, RR, RW> {
|
||||
// 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<A, ER, RR>
|
||||
// readonly changes: Stream.Stream<A, ER, RR>
|
||||
// readonly update: (a: A) => Effect.Effect<void, EW, RW>
|
||||
// readonly withLock: <A1, E1, R1>(self: Effect.Effect<A1, E1, R1>) => Effect.Effect<A1, EW | E1, RW | R1>
|
||||
|
||||
// constructor(
|
||||
// source: LensImpl.Source<A, ER, EW, RR, RW>
|
||||
// ) {
|
||||
// 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<A, ER, EW, RR, RW> {
|
||||
|
||||
// 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 = <A, ER, EW, RR, RW>(
|
||||
source: LensImpl.Source<A, ER, EW, RR, RW>
|
||||
): Lens<A, ER, EW, RR, RW> => new LensImpl(source)
|
||||
|
||||
|
||||
// export class LensLazyImpl<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never>
|
||||
// extends Pipeable.Class() implements LensWithInternals<A, ER, EW, RR, RW> {
|
||||
// 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<A, ER, EW, RR, RW>
|
||||
// ) {
|
||||
// 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<in out A>
|
||||
extends Pipeable.Class() implements LensWithInternals<A, never, never, never, never> {
|
||||
readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId
|
||||
readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId
|
||||
readonly [LensTypeId]: LensTypeId = LensTypeId
|
||||
readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId
|
||||
|
||||
extends LensImpl<A, A, never, never, never, never, never, never, never, never> {
|
||||
readonly ref: SynchronizedRefLensImpl.SynchronizedRefWithInternals<A>
|
||||
|
||||
constructor(
|
||||
@@ -230,12 +179,10 @@ extends Pipeable.Class() implements LensWithInternals<A, never, never, never, ne
|
||||
this.ref = ref as SynchronizedRefLensImpl.SynchronizedRefWithInternals<A>
|
||||
}
|
||||
|
||||
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<in out A>
|
||||
extends Pipeable.Class() implements LensWithInternals<A, never, never, never, never> {
|
||||
readonly [Readable.TypeId]: Readable.TypeId = Readable.TypeId
|
||||
readonly [Subscribable.TypeId]: Subscribable.TypeId = Subscribable.TypeId
|
||||
readonly [LensTypeId]: LensTypeId = LensTypeId
|
||||
readonly [LensWithInternalsTypeId]: LensWithInternalsTypeId = LensWithInternalsTypeId
|
||||
|
||||
extends LensImpl<A, A, never, never, never, never, never, never, never, never> {
|
||||
readonly ref: SubscriptionRefLensImpl.SubscriptionRefWithInternals<A>
|
||||
|
||||
constructor(
|
||||
@@ -274,17 +216,15 @@ extends Pipeable.Class() implements LensWithInternals<A, never, never, never, ne
|
||||
this.ref = ref as SubscriptionRefLensImpl.SubscriptionRefWithInternals<A>
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user