summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authordearblue <[email protected]>2019-01-01 13:15:48 +0900
committerdearblue <[email protected]>2019-01-03 18:16:26 +0900
commit9a9e12a1299181bc38abbb4e8dbb62569bcbc551 (patch)
tree7161d8b5deee0fabd161c5f7995feb09840201d5
parent3e59f25eef8faf2677071dfc1add7142e92549e7 (diff)
downloadmruby-9a9e12a1299181bc38abbb4e8dbb62569bcbc551.tar.gz
mruby-9a9e12a1299181bc38abbb4e8dbb62569bcbc551.zip
Add proc composition feature (CRuby-2.6 compatible)
- Proc#<< and Proc#>> - Method#<< and Method#>>
-rw-r--r--mrbgems/mruby-method/mrblib/method.rb8
-rw-r--r--mrbgems/mruby-proc-ext/mrblib/proc.rb8
2 files changed, 16 insertions, 0 deletions
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