Created
November 1, 2021 01:18
-
-
Save kalda341/8f1fcccb1a55bb0376369ab7a88da5f6 to your computer and use it in GitHub Desktop.
This file contains 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
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