diff --git a/packages/effect-lens/src/Lens.ts b/packages/effect-lens/src/Lens.ts
index 9355e9b..f6a213b 100644
--- a/packages/effect-lens/src/Lens.ts
+++ b/packages/effect-lens/src/Lens.ts
@@ -446,24 +446,27 @@ export const mapErrorRead: {
/**
* Transforms modify errors of a `Lens`.
*
- * Applies to the `modify` effect. Since `modify` may also fail with errors coming from the
- * user-supplied callback, the handler receives `unknown`.
+ * Applies to the commit/rebuild portion of `modifyEffect` while leaving failures from the
+ * user-supplied callback unchanged.
*/
export const mapErrorWrite: {
(
self: Lens,
- f: (error: unknown) => E2,
+ f: (error: NoInfer) => E2,
): Lens
(
- f: (error: unknown) => E2,
+ f: (error: NoInfer) => E2,
): (self: Lens) => Lens
} = Function.dual(2, (
self: Lens,
- f: (error: unknown) => E2,
+ f: (error: NoInfer) => E2,
): Lens => derive(self, {
resolve: parent => Effect.map(parent, frame => ({
value: frame.value,
- commit: next => Effect.mapError(frame.commit(next), f),
+ commit: next => Effect.flatMap(
+ next,
+ value => Effect.mapError(frame.commit(Effect.succeed(value)), f),
+ ),
})),
transformStream: identity,
}))
@@ -471,26 +474,29 @@ export const mapErrorWrite: {
/**
* Transforms all errors of a `Lens`.
*
- * Applies to `get`, `changes`, and `modify`. Since `modify` may also fail with errors coming
- * from the user-supplied callback, the handler receives `unknown`.
+ * Applies to `get`, `changes`, and the commit/rebuild portion of `modifyEffect` while leaving
+ * failures from the user-supplied callback unchanged.
*/
export const mapError: {
(
self: Lens,
- f: (error: unknown) => E2,
+ f: (error: NoInfer) => E2,
): Lens
(
- f: (error: unknown) => E2,
+ f: (error: NoInfer) => E2,
): (self: Lens) => Lens
} = Function.dual(2, (
self: Lens,
- f: (error: unknown) => E2,
+ f: (error: NoInfer) => E2,
): Lens => derive(self, {
resolve: parent => Effect.map(
Effect.mapError(parent, f),
frame => ({
value: frame.value,
- commit: next => Effect.mapError(frame.commit(next), f),
+ commit: next => Effect.flatMap(
+ next,
+ value => Effect.mapError(frame.commit(Effect.succeed(value)), f),
+ ),
}),
),
transformStream: Stream.mapError(f),
@@ -528,18 +534,21 @@ export const catchAllRead: {
export const catchAllWrite: {
(
self: Lens,
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens
(
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): (self: Lens) => Lens
} = Function.dual(2, (
self: Lens,
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens => derive(self, {
resolve: parent => Effect.map(parent, frame => ({
value: frame.value,
- commit: next => Effect.catchAll(frame.commit(next), f),
+ commit: next => Effect.flatMap(
+ next,
+ value => Effect.catchAll(frame.commit(Effect.succeed(value)), f),
+ ),
})),
transformStream: identity,
}))
@@ -552,14 +561,14 @@ export const catchAllWrite: {
export const tapErrorRead: {
(
self: Lens,
- f: (error: NoInfer) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens
(
- f: (error: NoInfer) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): (self: Lens) => Lens
} = Function.dual(2, (
self: Lens,
- f: (error: NoInfer) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens => derive(self, {
resolve: Effect.tapError(f),
transformStream: Stream.tapError(f),
@@ -568,24 +577,27 @@ export const tapErrorRead: {
/**
* Runs an effect when modify failures occur.
*
- * Applies to the `modify` effect. Since `modify` may also fail with errors coming from the
- * user-supplied callback, the handler receives `unknown`.
+ * Applies to the commit/rebuild portion of `modifyEffect` while leaving failures from the
+ * user-supplied callback unchanged.
*/
export const tapErrorWrite: {
(
self: Lens,
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens
(
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): (self: Lens) => Lens
} = Function.dual(2, (
self: Lens,
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens => derive(self, {
resolve: parent => Effect.map(parent, frame => ({
value: frame.value,
- commit: next => Effect.tapError(frame.commit(next), f),
+ commit: next => Effect.flatMap(
+ next,
+ value => Effect.tapError(frame.commit(Effect.succeed(value)), f),
+ ),
})),
transformStream: identity,
}))
@@ -593,26 +605,29 @@ export const tapErrorWrite: {
/**
* Runs an effect when any `Lens` failure occurs.
*
- * Applies to `get`, `changes`, and `modify`. Since `modify` may also fail with errors coming
- * from the user-supplied callback, the handler receives `unknown`.
+ * Applies to `get`, `changes`, and the commit/rebuild portion of `modifyEffect` while leaving
+ * failures from the user-supplied callback unchanged.
*/
export const tapError: {
(
self: Lens,
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens
(
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): (self: Lens) => Lens
} = Function.dual(2, (
self: Lens,
- f: (error: unknown) => Effect.Effect,
+ f: (error: NoInfer) => Effect.Effect,
): Lens => derive(self, {
resolve: parent => Effect.map(
Effect.tapError(parent, f),
frame => ({
value: frame.value,
- commit: next => Effect.tapError(frame.commit(next), f),
+ commit: next => Effect.flatMap(
+ next,
+ value => Effect.tapError(frame.commit(Effect.succeed(value)), f),
+ ),
}),
),
transformStream: Stream.tapError(f),