Skip to content

Instantly share code, notes, and snippets.

@gmmorris
Last active January 6, 2017 12:01
Show Gist options
  • Save gmmorris/8e70c6f5857a4329088a to your computer and use it in GitHub Desktop.
Save gmmorris/8e70c6f5857a4329088a to your computer and use it in GitHub Desktop.
Example of how to fix the original function using the safe function
const safeDarthVader = safe({
name : 'Anakin',
mother : {
name : 'Shmi'
}
});
function getFatherName(person) {
return person.father.name
}
function getName(person) {
return person.name
}
let darthVadersFather = either(getFatherName(safeDarthVader), `${getName(safeDarthVader)} has no father`);
console.log(darthVadersFather); // Prints 'Anakin has no father'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment