From 9a9e12a1299181bc38abbb4e8dbb62569bcbc551 Mon Sep 17 00:00:00 2001 From: dearblue Date: Tue, 1 Jan 2019 13:15:48 +0900 Subject: Add proc composition feature (CRuby-2.6 compatible) - Proc#<< and Proc#>> - Method#<< and Method#>> --- mrbgems/mruby-method/mrblib/method.rb | 8 ++++++++ mrbgems/mruby-proc-ext/mrblib/proc.rb | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/mrbgems/mruby-method/mrblib/method.rb b/mrbgems/mruby-method/mrblib/method.rb index 5de0afdf7..f7cefa2e5 100644 --- a/mrbgems/mruby-method/mrblib/method.rb +++ b/mrbgems/mruby-method/mrblib/method.rb @@ -17,4 +17,12 @@ class Method def name @name end + + def <<(other) + ->(*args, &block) { call(other.call(*args, &block)) } + end + + def >>(other) + ->(*args, &block) { other.call(call(*args, &block)) } + end end diff --git a/mrbgems/mruby-proc-ext/mrblib/proc.rb b/mrbgems/mruby-proc-ext/mrblib/proc.rb index 789b7a3ac..abe9c7944 100644 --- a/mrbgems/mruby-proc-ext/mrblib/proc.rb +++ b/mrbgems/mruby-proc-ext/mrblib/proc.rb @@ -39,4 +39,12 @@ class Proc make_curry.call end + def <<(other) + ->(*args, &block) { call(other.call(*args, &block)) } + end + + def >>(other) + ->(*args, &block) { other.call(call(*args, &block)) } + end + end -- cgit v1.2.3