Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # the return of the one, is the param of the next
- one = ->(value) { puts "received #{value}"; 1 }
- two = ->(value) { puts "received #{value}"; 2 }
- three = ->(value) { puts "received #{value}"; 3 }
- done = one >> two >> three
- puts "-" * 10
- puts "finalizing #{done.call("calling")}"
- puts "-" * 10
- # for example...
- apply_discount = ->(price) {
- price - (price * 0.1)
- }
- apply_coupon = -> (price) {
- price - (price * 0.1)
- }
- apply_taxes = ->(price) {
- price + (price * 0.06)
- }
- notify = -> (price) {
- puts "omg! so notified #{price}"
- price
- }
- discount = apply_taxes >> apply_discount
- puts "discount #{discount.call 100}"
- puts "-" * 10
- coupon = apply_taxes >> apply_coupon
- puts "coupon #{coupon.call 100}"
- puts "-" * 10
- mega_discout = apply_taxes >> apply_coupon >> apply_discount
- puts "mega_discount #{mega_discout.call 100}"
- puts "-" * 10
- discount_and_notify = discount >> notify
- puts "discount and notify #{discount_and_notify.call 100}"
- puts "-" * 10
- reveeerse = apply_taxes << notify
- puts "reveeerse #{reveeerse.call 100}"
- puts "-" * 10
- ### for a more down to earth
- # get(url) >> extract_price >> apply_discount >> ...
Add Comment
Please, Sign In to add comment