Skip to content

Instantly share code, notes, and snippets.

@MikelArnaiz
Created July 5, 2021 07:05
Show Gist options
  • Save MikelArnaiz/ffe39c7582e332f017eab558ddd9bb40 to your computer and use it in GitHub Desktop.
Save MikelArnaiz/ffe39c7582e332f017eab558ddd9bb40 to your computer and use it in GitHub Desktop.
Decode expected JSON and map it to expected result
// Attempt 1
function decodeJson(json: unknown) {
return <A, R>(
expectedInput: Decoder<unknown, A>,
expectedOutput: Decoder<unknown, R>,
fn: (a: A) => R
): Either.Either<Decoding, R> => {
pipe(
json,
decodeWith(expectedInput),
Either.mapLeft((err) => err as Decoding),
Either.match(
notifyHoneybadgerDecodingError('RealTime Decoding Error'),
noop
)
);
return pipe(
fn(json as A),
decodeWith(expectedOutput),
Either.mapLeft((err) => err as Decoding)
);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment