Guest User

Untitled

a guest
Jan 18th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. # the return of the one, is the param of the next
  2. one = ->(value) { puts "received #{value}"; 1 }
  3. two = ->(value) { puts "received #{value}"; 2 }
  4. three = ->(value) { puts "received #{value}"; 3 }
  5. done = one >> two >> three
  6. puts "-" * 10
  7. puts "finalizing #{done.call("calling")}"
  8. puts "-" * 10
  9.  
  10. # for example...
  11. apply_discount = ->(price) {
  12. price - (price * 0.1)
  13. }
  14.  
  15. apply_coupon = -> (price) {
  16. price - (price * 0.1)
  17. }
  18.  
  19. apply_taxes = ->(price) {
  20. price + (price * 0.06)
  21. }
  22.  
  23. notify = -> (price) {
  24. puts "omg! so notified #{price}"
  25. price
  26. }
  27.  
  28. discount = apply_taxes >> apply_discount
  29. puts "discount #{discount.call 100}"
  30. puts "-" * 10
  31.  
  32. coupon = apply_taxes >> apply_coupon
  33. puts "coupon #{coupon.call 100}"
  34. puts "-" * 10
  35.  
  36. mega_discout = apply_taxes >> apply_coupon >> apply_discount
  37. puts "mega_discount #{mega_discout.call 100}"
  38. puts "-" * 10
  39.  
  40. discount_and_notify = discount >> notify
  41. puts "discount and notify #{discount_and_notify.call 100}"
  42. puts "-" * 10
  43.  
  44. reveeerse = apply_taxes << notify
  45. puts "reveeerse #{reveeerse.call 100}"
  46. puts "-" * 10
  47.  
  48. ### for a more down to earth
  49. # get(url) >> extract_price >> apply_discount >> ...
Add Comment
Please, Sign In to add comment