Created
August 11, 2016 20:48
-
-
Save lightsofapollo/b8352ea0f1d2c1b82622c90b3d8094e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type Result<E, V> = [null, V] | [E, null]; | |
const emailList = ['[email protected]']; | |
function searchForEmail(email: string): Result<Error, bool> { | |
if (email.indexOf('@') === -1) { | |
return [new Error('this is not an email'), null]; | |
} | |
// here we would do an actual search for the email ... | |
return [null, emailList.indexOf(email) !== -1]; | |
} | |
const [err, hasEmail] = searchForEmail('[email protected]'); | |
if (err) { | |
console.log(`invalid email: ${err.stack}`); | |
} else { | |
console.log('found email address: ', hasEmail); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment