@@ -12,7 +12,7 @@ export type LensTypeId = typeof LensTypeId
|
||||
* 2. a `changes` stream that emits every subsequent update to `A`, and
|
||||
* 3. a `modify` effect that can transform the current value.
|
||||
*/
|
||||
export interface Lens<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never>
|
||||
export interface Lens<in out A, out ER = never, out EW = never, out RR = never, out RW = never>
|
||||
extends View.View<A, ER, RR> {
|
||||
readonly [LensTypeId]: LensTypeId
|
||||
|
||||
@@ -35,7 +35,7 @@ export const LensImplTypeId: unique symbol = Symbol.for("@effect-fc/Lens/v4/Lens
|
||||
export type LensImplTypeId = typeof LensImplTypeId
|
||||
|
||||
export declare namespace LensImpl {
|
||||
export interface Resolved<in out A, in out EW = never, in out RW = never> {
|
||||
export interface Resolved<in out A, out EW = never, out RW = never> {
|
||||
readonly value: A
|
||||
readonly commit: <E = never, R = never>(
|
||||
next: Effect.Effect<A, E, R>
|
||||
@@ -47,7 +47,7 @@ export declare namespace LensImpl {
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class LensImpl<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never>
|
||||
export abstract class LensImpl<in out A, out ER = never, out EW = never, out RR = never, out RW = never>
|
||||
extends Pipeable.Class implements Lens<A, ER, EW, RR, RW> {
|
||||
readonly [View.ViewTypeId]: View.ViewTypeId = View.ViewTypeId
|
||||
readonly [LensTypeId]: LensTypeId = LensTypeId
|
||||
@@ -109,7 +109,7 @@ export const asView = <A, ER, EW, RR, RW>(
|
||||
|
||||
|
||||
export declare namespace LensLazyImpl {
|
||||
export interface Source<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never> {
|
||||
export interface Source<in out A, out ER = never, out EW = never, out RR = never, out RW = never> {
|
||||
readonly get: Effect.Effect<A, ER, RR>
|
||||
readonly changes: Stream.Stream<A, ER, RR>
|
||||
readonly commit: (a: A) => Effect.Effect<void, EW, RW>
|
||||
@@ -117,7 +117,7 @@ export declare namespace LensLazyImpl {
|
||||
}
|
||||
}
|
||||
|
||||
export class LensLazyImpl<in out A, in out ER = never, in out EW = never, in out RR = never, in out RW = never>
|
||||
export class LensLazyImpl<in out A, out ER = never, out EW = never, out RR = never, out RW = never>
|
||||
extends LensImpl<A, ER, EW, RR, RW> {
|
||||
constructor(
|
||||
readonly source: LensLazyImpl.Source<A, ER, EW, RR, RW>,
|
||||
@@ -146,7 +146,7 @@ export const make = <A, ER, EW, RR, RW>(
|
||||
): Lens<A, ER, EW, RR, RW> => new LensLazyImpl(source)
|
||||
|
||||
|
||||
export class UnwrappedLensImpl<in out A, in out ER, in out EW, in out RR, in out RW, in out E1, in out R1>
|
||||
export class UnwrappedLensImpl<in out A, out ER, out EW, out RR, out RW, out E1, out R1>
|
||||
extends LensImpl<A, ER | E1, EW | E1, RR | R1, RW | R1> {
|
||||
constructor(
|
||||
readonly effect: Effect.Effect<Lens<A, ER, EW, RR, RW>, E1, R1>
|
||||
|
||||
@@ -72,6 +72,29 @@ describe("View", () => {
|
||||
expect(result).toEqual(["fallback", ["fallback"]])
|
||||
})
|
||||
|
||||
test("zipLatestAll combines current values and change streams", async () => {
|
||||
const zipped = View.zipLatestAll(
|
||||
View.make({
|
||||
get: Effect.succeed(1),
|
||||
changes: Stream.succeed(2),
|
||||
}),
|
||||
View.make({
|
||||
get: Effect.succeed("one"),
|
||||
changes: Stream.succeed("two"),
|
||||
}),
|
||||
)
|
||||
|
||||
const result = await Effect.runPromise(Effect.all([
|
||||
zipped.get,
|
||||
Stream.runCollect(zipped.changes),
|
||||
]))
|
||||
|
||||
expect([result[0], Array.from(result[1])]).toEqual([
|
||||
[1, "one"],
|
||||
[[2, "two"]],
|
||||
])
|
||||
})
|
||||
|
||||
test("focusArrayLength reads the current array length and reflects updates", async () => {
|
||||
const result = await Effect.runPromise(
|
||||
Effect.flatMap(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Array, type Cause, Chunk, Effect, Function, Iterable, Option, Pipeable,
|
||||
export const ViewTypeId: unique symbol = Symbol.for("@effect-lens/View/View")
|
||||
export type ViewTypeId = typeof ViewTypeId
|
||||
|
||||
export interface View<in out A, in out E = never, in out R = never> extends Pipeable.Pipeable {
|
||||
export interface View<out A, out E = never, out R = never> extends Pipeable.Pipeable {
|
||||
readonly [ViewTypeId]: ViewTypeId
|
||||
readonly get: Effect.Effect<A, E, R>
|
||||
readonly changes: Stream.Stream<A, E, R>
|
||||
@@ -17,13 +17,13 @@ export const ViewImplTypeId: unique symbol = Symbol.for("@effect-fc/Lens/v4/View
|
||||
export type ViewImplTypeId = typeof ViewImplTypeId
|
||||
|
||||
export declare namespace ViewImpl {
|
||||
export interface Source<in out A, in out E = never, in out R = never> {
|
||||
export interface Source<out A, out E = never, out R = never> {
|
||||
readonly get: Effect.Effect<A, E, R>
|
||||
readonly changes: Stream.Stream<A, E, R>
|
||||
}
|
||||
}
|
||||
|
||||
export class ViewImpl<in out A, in out E = never, in out R = never>
|
||||
export class ViewImpl<out A, out E = never, out R = never>
|
||||
extends Pipeable.Class implements View<A, E, R> {
|
||||
readonly [ViewTypeId]: ViewTypeId = ViewTypeId
|
||||
readonly [ViewImplTypeId]: ViewImplTypeId = ViewImplTypeId
|
||||
|
||||
@@ -71,6 +71,29 @@ describe("Subscribable", () => {
|
||||
expect(result).toEqual(["fallback", ["fallback"]])
|
||||
})
|
||||
|
||||
test("zipLatestAll combines current values and change streams", async () => {
|
||||
const zipped = Subscribable.zipLatestAll(
|
||||
Subscribable.make({
|
||||
get: Effect.succeed(1),
|
||||
changes: Stream.succeed(2),
|
||||
}),
|
||||
Subscribable.make({
|
||||
get: Effect.succeed("one"),
|
||||
changes: Stream.succeed("two"),
|
||||
}),
|
||||
)
|
||||
|
||||
const result = await Effect.runPromise(Effect.all([
|
||||
zipped.get,
|
||||
Stream.runCollect(zipped.changes),
|
||||
]))
|
||||
|
||||
expect([result[0], Array.from(result[1])]).toEqual([
|
||||
[1, "one"],
|
||||
[[2, "two"]],
|
||||
])
|
||||
})
|
||||
|
||||
test("focusArrayLength reads the current array length and reflects updates", async () => {
|
||||
const result = await Effect.runPromise(
|
||||
Effect.flatMap(
|
||||
|
||||
Reference in New Issue
Block a user