Skip to content

Instantly share code, notes, and snippets.

@Yama-Tomo
Created July 2, 2020 00:29
Show Gist options
  • Save Yama-Tomo/07504a1c3c3be70a9f913d1b2c6615ed to your computer and use it in GitHub Desktop.
Save Yama-Tomo/07504a1c3c3be70a9f913d1b2c6615ed to your computer and use it in GitHub Desktop.
pipeline operator like in ruby
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