Skip to content

Instantly share code, notes, and snippets.

@dgieselaar
Created September 9, 2019 20:47
Show Gist options
  • Save dgieselaar/fc5f48b25fa0a6a8d205b07ec4e845b5 to your computer and use it in GitHub Desktop.
Save dgieselaar/fc5f48b25fa0a6a8d205b07ec4e845b5 to your computer and use it in GitHub Desktop.
import { pipe } from 'fp-ts/lib/pipeable';
import { fold } from 'fp-ts/lib/Either';
import codec from './codec.ts';
const input = {
title: 'Title of this article',
content: 'Content of this article',
options: {
private: true
}
};
const result = pipe(
codec.decode(input),
fold(
() => {
throw new Error('Input validation error');
},
val => val
)
);
/*
right = {
title: string,
content: string,
options: {
private?: boolean
}
}
*/
const { right } = result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment