Last active
January 13, 2017 12:40
-
-
Save saginadir/dd2aee798f2f34dd3663bb53a7027486 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 wrap = (student) => ({ | |
take: (item) => { | |
student.items.push(item); | |
return wrap(student); | |
}, | |
giveHomework: (homeworkQuantity) => { | |
student.homeworkQuantity += homeworkQuantity; | |
return wrap(student); | |
}, | |
doHomework: () => { | |
const doneHomework = student.items.reduce((done, item) => { | |
if(item === 'pencil') { | |
student.homeworkQuantity -= 1; | |
return true; | |
} | |
return doneHomework; | |
}, false) | |
if(!doneHomework) console.log('Missing pencil to do homework'); | |
return wrap(student); | |
}, | |
logMyState: () => { | |
console.log(student); | |
return wrap(student); | |
} | |
}); | |
const newStudent = (name) => wrap({ | |
name, | |
items: [], | |
homeworkQuantity: 0, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment