Last active
January 18, 2019 11:27
-
-
Save mistersourcerer/dc696ad64e4a0d751fb73b5ac26d85a6 to your computer and use it in GitHub Desktop.
This file contains 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
# 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 >> ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment