Skip to content

Instantly share code, notes, and snippets.

@fetchTe
Created March 11, 2016 21:21
Show Gist options
  • Save fetchTe/356f4b5897cab404751a to your computer and use it in GitHub Desktop.
Save fetchTe/356f4b5897cab404751a to your computer and use it in GitHub Desktop.

Either Example

const divide = R.curry(function (a, b) {
  return b === 0 ? Either.Left('Dicision by 0.') : Either.Right(a / b);
});

const addTwo = R.curry(function (val) {
  return val + 2;
});

let divideTwo = R.compose(map(addTwo), divide(2));

let two = divideTwo(2); // Right.val{4}
let zero = divideTwo(0); // Left.val{err}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment