Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Egg() {...}
- // the curry func
- function prepareCooking(cook) {
- return function(egg1) {
- return function(egg2) {
- return function(egg3) {
- return function(egg4) {
- return cook(egg1, egg2, egg3, egg4)
- }
- }
- }
- }
- }
- const cook = function(...eggs) {
- api.turnOnStove()
- api.putEggsOnTop(...eggs)
- api.pourSalt()
- api.serve()
- console.log('served children')
- return 'served'
- }
- const start = prepareCooking(cook)
- let collect = start(new Egg())
- collect = collect(new Egg())
- collect = collect(new Egg())
- collect = collect(new Egg()) // this steps into the last function witih argument "egg4" which will invoke the callback passed to "prepareCooking"
- // result: console.log --> "served children"
- // collect === 'served'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement