Skip to content

Instantly share code, notes, and snippets.

@tgrecojs
Created June 25, 2020 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tgrecojs/a682e704905863bd4267fbf3d83e1754 to your computer and use it in GitHub Desktop.
Save tgrecojs/a682e704905863bd4267fbf3d83e1754 to your computer and use it in GitHub Desktop.
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');
@wayneseymour
Copy link

yeah looks great to me! On to applicative functors! :)

@tgrecojs
Copy link
Author

yeah looks great to me! On to applicative functors! :)

oh yeah 😎 now the REAL heavy "lifting" begins... cheesy pun intended (couldn't help myself)

@wayneseymour
Copy link

hahahahahaaa a2! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment