Created
June 25, 2020 19:34
-
-
Save tgrecojs/a682e704905863bd4267fbf3d83e1754 to your computer and use it in GitHub Desktop.
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
const Maybe = { | |
Just: value => ({ | |
value, | |
map: f => Just(f(value)), | |
toString: () => `Just(${value})` | |
}), | |
Nothing: (value = null) => ({ | |
value: null, | |
map: f => Nothing(null), | |
toString: () => `Nothing(${value})` | |
}) | |
} | |
const Either = { | |
Right: value => ({ | |
value, | |
map: f => Right(f(value)), | |
toString: () => `Right(${value})` | |
}), | |
Left: value => ({ | |
value, | |
map: f => Left(value), | |
toString: () => `Left(${value})` | |
}), | |
} | |
const{ Just, Nothing } = Maybe; | |
const { Left, Right } = Either; | |
/** | |
* | |
*/ | |
const maybeTotal = (x) => (x === 'total' ? Just(x) : Nothing()); | |
const eitherTotal = x => x === 'total' ? Right(x) : Left('Input is not valid'); | |
yeah looks great to me! On to applicative functors! :)
oh yeah 😎 now the REAL heavy "lifting" begins... cheesy pun intended (couldn't help myself)
hahahahahaaa a2! :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yeah looks great to me! On to applicative functors! :)