diff --git a/packages/effect-lens/src/Lens.test.ts b/packages/effect-lens/src/Lens.test.ts index 6d5613a..57eee62 100644 --- a/packages/effect-lens/src/Lens.test.ts +++ b/packages/effect-lens/src/Lens.test.ts @@ -83,7 +83,7 @@ describe("Lens", () => { test("focusTupleAt updates the selected tuple index immutably", async () => { const updated = await Effect.runPromise( Effect.flatMap( - SubscriptionRef.make(["a", "b", "c"] as const), + SubscriptionRef.make(["a", "b", "c"]), parent => { const elementLens = Lens.focusTupleAt(Lens.fromSubscriptionRef(parent), 1) return Effect.flatMap( @@ -98,7 +98,7 @@ describe("Lens", () => { }) test("focusMutableTupleAt mutates the tuple reference in place", async () => { - const original = ["foo", "bar"] as ["foo", "bar"] + const original: [string, string] = ["foo", "bar"] const updated = await Effect.runPromise( Effect.flatMap( SubscriptionRef.make(original), diff --git a/packages/effect-lens/src/Lens.ts b/packages/effect-lens/src/Lens.ts index d7f7c6f..679e0dc 100644 --- a/packages/effect-lens/src/Lens.ts +++ b/packages/effect-lens/src/Lens.ts @@ -300,43 +300,40 @@ export const focusMutableArrayAt: { * Narrows the focus to an indexed element of a readonly tuple. Replaces the tuple in an immutable fashion when written to. */ export const focusTupleAt: { - ( + ( self: Lens, - index: number, - ): Lens - ( - index: number - ): (self: Lens) => Lens -} = Function.dual(2, ( + index: I, + ): Lens + ( + index: I + ): (self: Lens) => Lens +} = Function.dual(2, ( self: Lens, - index: number, -): Lens => mapEffect( + index: I, +): Lens => map( self, - Array.get(index), - (a, b) => Array.replaceOption(a, index, b) as any, + Array.unsafeGet(index), + (a, b) => Array.replace(a, index, b) as any, )) /** * Narrows the focus to an indexed element of a mutable tuple. Mutates the tuple in place when written to. */ export const focusMutableTupleAt: { - ( + ( self: Lens, - index: number, - ): Lens - ( - index: number - ): (self: Lens) => Lens -} = Function.dual(2, ( + index: I, + ): Lens + ( + index: I + ): (self: Lens) => Lens +} = Function.dual(2, ( self: Lens, - index: number, -): Lens => mapEffect( + index: I, +): Lens => map( self, - Array.get(index), - (a, b) => Effect.flatMap( - Array.get(a, index), - () => Effect.as(Effect.sync(() => { a[index] = b }), a), - ), + Array.unsafeGet(index), + (a, b) => { a[index] = b; return a }, )) /**