Last active
January 6, 2017 12:01
-
-
Save gmmorris/8e70c6f5857a4329088a to your computer and use it in GitHub Desktop.
Example of how to fix the original function using the safe function
This file contains 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 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