Created
July 2, 2020 00:29
-
-
Save Yama-Tomo/07504a1c3c3be70a9f913d1b2c6615ed to your computer and use it in GitHub Desktop.
pipeline operator like in ruby
This file contains hidden or 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
def pipe(arg) | |
->(fn = nil) { !fn.nil? && fn.is_a?(Proc) ? pipe(fn.call(arg)) : arg } | |
end | |
# usage | |
pipe(1) | |
.call(->(arg) { arg + 1 }) | |
.call(->(arg) { arg * 3 }) | |
.call |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment