Skip to content

Instantly share code, notes, and snippets.

@donabrams
Last active November 20, 2017 20:40
Show Gist options
  • Save donabrams/7e25f5921f33ff49947830e9cfa6ad9f to your computer and use it in GitHub Desktop.
Save donabrams/7e25f5921f33ff49947830e9cfa6ad9f to your computer and use it in GitHub Desktop.
choice.js - OOP Either
const choice = (decision) => {
let yes = () => {};
let no = () => {};
const a = {
yes: (f) => { yes = f; return a; },
no: (f) => { no = f; return a; },
decide: () => {
const next = decision() ? yes() : no();
return next.decide ? next.decide() : next;
}
};
return a;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment