Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. function Egg() {...}
  2.  
  3. // the curry func
  4. function prepareCooking(cook) {
  5. return function(egg1) {
  6. return function(egg2) {
  7. return function(egg3) {
  8. return function(egg4) {
  9. return cook(egg1, egg2, egg3, egg4)
  10. }
  11. }
  12. }
  13. }
  14. }
  15.  
  16. const cook = function(...eggs) {
  17. api.turnOnStove()
  18. api.putEggsOnTop(...eggs)
  19. api.pourSalt()
  20. api.serve()
  21. console.log('served children')
  22. return 'served'
  23. }
  24.  
  25. const start = prepareCooking(cook)
  26.  
  27. let collect = start(new Egg())
  28. collect = collect(new Egg())
  29. collect = collect(new Egg())
  30. collect = collect(new Egg()) // this steps into the last function witih argument "egg4" which will invoke the callback passed to "prepareCooking"
  31.  
  32. // result: console.log --> "served children"
  33. // collect === 'served'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement