Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const checkUsername = auth => auth.username
- ? Right.of(auth)
- : Left.of('No Username')
- const checkPassword = auth => auth.password
- ? Right.of(auth)
- : Left.of('Password Empty')
- const validateLogin = (auth, constraints) => {
- const checkMatch = auth => (auth.username === 'jihad' && auth.password === 'jihad123')
- ? Right.of(auth.username)
- : Left.of('Username && password mismatch')
- const formatError = e => `error: ${e}`
- const successfulMsg = username => `Welcome back, ${username}!`
- const composed = constraints.reduce((acc, cons) => acc.bind(cons), Either.of(auth))
- return composed
- .bind(checkMatch)
- .cata(formatError, successfulMsg)
- }
- const validateRegister = (auth, constraints) => { ... }
- validateLogin(auth, [checkUsername, checkPassword, etc])()
- validateRegister(auth, [checkUsername, checkPassword, etc])()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement