We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2877e99 commit 466e15aCopy full SHA for 466e15a
src/decoder.ts
@@ -730,6 +730,14 @@ export class Decoder<A> {
730
map = <B>(f: (value: A) => B): Decoder<B> =>
731
new Decoder((json, context) => Result.map(f, this.decode(json, context)));
732
733
+ /**
734
+ * Construct a new decoder that applies a transformation to an error message
735
+ * on failure. If the decoder fails then `f` will be applied to the error. If
736
+ * it succeeds the value will propagated through.
737
+ */
738
+ mapError = (f: (error: DecoderError) => DecoderError): Decoder<A> =>
739
+ new Decoder((json, context) => Result.mapError(f, this.decode(json, context)));
740
+
741
/**
742
* Chain together a sequence of decoders. The first decoder will run, and
743
* then the function will determine what decoder to run second. If the result
0 commit comments