Skip to content

Instantly share code, notes, and snippets.

@kalda341
Created November 1, 2021 01:18
Show Gist options
  • Save kalda341/8f1fcccb1a55bb0376369ab7a88da5f6 to your computer and use it in GitHub Desktop.
Save kalda341/8f1fcccb1a55bb0376369ab7a88da5f6 to your computer and use it in GitHub Desktop.
import "./styles.css";
import { function as F, option as O, either as E, readonlyArray as A, monoid as Monoid, readonlyNonEmptyArray as NEA } from 'fp-ts';
import { some } from "fp-ts/lib/ReadonlyRecord";
const invert = (x: number): E.Either<string, number> => {
if (x === 0) {
return E.left("Cannot divide by 0");
} else {
return E.right(1 / x);
}
}
const addOne = (x: number): number => x + 1;
const result = F.pipe(
invert(0),
E.map(addOne),
E.map(addOne),
E.map(addOne),
E.chain(invert),
E.chain(invert),
E.chain(invert),
E.fold(
(x) => <p>An error occured: ${x}</p>,
(x) => <p>x</p>
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment