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"] |
This comment has been minimized.
This comment has been minimized.
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
This comment has been minimized.
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.