Skip to content

Instantly share code, notes, and snippets.

@dewey92
Last active June 23, 2017 16:07
Show Gist options
  • Select an option

  • Save dewey92/1555a43dcf28255a0027f8c795e0fb7e to your computer and use it in GitHub Desktop.

Select an option

Save dewey92/1555a43dcf28255a0027f8c795e0fb7e to your computer and use it in GitHub Desktop.
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