Last active
August 15, 2018 17:29
-
-
Save havenwood/d305b42f5b542e9de1eaa8e56ba6bdd7 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
class Proc | |
def >> other | |
-> arg { other.to_proc.call call arg } | |
end | |
def << other | |
-> arg { call other.to_proc.call arg } | |
end | |
end | |
add_forty_two = -> x { x + 42 } | |
[1, 3, 6].map &:abs2.to_proc << add_forty_two | |
#=> [1849, 2025, 2304] | |
[1, 3, 6].map &:abs2.to_proc >> add_forty_two | |
#=> [43, 51, 78] | |
[:hi, :there].map &:to_s.to_proc << :upcase | |
#=> ["HI", "THERE"] | |
[:hi, :there].map &:to_s.to_proc >> :upcase >> :reverse | |
#=> ["IH", "EREHT"] | |
[:hi, :there].map &:reverse.to_proc << :upcase << :to_s | |
#=> ["IH", "EREHT"] |
Ah, interesting. Thank you for the feedback! I'll update the gist.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like
Proc#>>
andProc#<<
are swapped - results are not the same as in comments.Symbol methods are not required, because only first symbol need to be converted explicitly:
This is be better because symbols should not be tied with functional computations. At least in stdlib.