Created
July 5, 2021 07:05
-
-
Save MikelArnaiz/ffe39c7582e332f017eab558ddd9bb40 to your computer and use it in GitHub Desktop.
Decode expected JSON and map it to expected result
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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