Either/IO Exercise 1

In notebook:
FrontEndMasters Hardcore Functional
Created at:
2017-04-06
Updated:
2017-04-06
Tags:
Functional Programming JavaScript

jsbin.com/zegat/7/edit

This is the exercise: jsbin.com/bexuc/1/edit

##First exercise

  // Exercise 1
// ==========
// Write a function that uses checkActive() and showWelcome() to grant access or return the error
console.log("--------Start exercise 1--------")

var showWelcome = compose(_.add( "Welcome "), _.get('name'))

var checkActive = function(user) {
 return user.active ? Right(user) : Left('Your account is not active')
}

var ex1 = undefined
// the solution
var ex1 = compose(map(showWelcome), checkActive)

assertDeepEqual(Left('Your account is not active'), ex1({active: false, name: 'Gary'}))
assertDeepEqual(Right('Welcome Theresa'), ex1({active: true, name: 'Theresa'}))
console.log("exercise 1...ok!")