Last active
June 23, 2017 16:07
-
-
Save dewey92/1555a43dcf28255a0027f8c795e0fb7e 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
| const validateLogin = auth => { | |
| const checkUsername = auth => auth.username | |
| ? Right(auth) | |
| : Left('No Username') | |
| const checkPassword = auth => auth.password | |
| ? Right(auth) | |
| : Left('Password Empty') | |
| const checkMatch = auth => (auth.username === 'jihad' && auth.password === 'jihad123') | |
| ? Right(auth.username) | |
| : Left('Username && password mismatch') | |
| const formatError = e => `error: ${e}` | |
| const successfulMsg = username => `Welcome back, ${username}!` | |
| return Either.of(auth) | |
| .bind(checkUsername) | |
| .bind(checkPassword) | |
| .bind(checkMatch) | |
| .cata(formatError, successfulMsg) | |
| } | |
| console.log(validateLogin(auth)()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment