summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-proc-ext
diff options
context:
space:
mode:
Diffstat (limited to 'mrbgems/mruby-proc-ext')
-rw-r--r--mrbgems/mruby-proc-ext/mrblib/proc.rb8
-rw-r--r--mrbgems/mruby-proc-ext/test/proc.rb13
2 files changed, 21 insertions, 0 deletions
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
diff --git a/mrbgems/mruby-proc-ext/test/proc.rb b/mrbgems/mruby-proc-ext/test/proc.rb
index 3e64bc103..1220841c8 100644
--- a/mrbgems/mruby-proc-ext/test/proc.rb
+++ b/mrbgems/mruby-proc-ext/test/proc.rb
@@ -77,6 +77,19 @@ assert('Kernel#proc') do
end
end
+assert "Proc#<< and Proc#>>" do
+ add3 = ->(n) { n + 3 }
+ mul2 = ->(n) { n * 2 }
+
+ f1 = mul2 << add3
+ assert_kind_of Proc, f1
+ assert_equal 16, f1.call(5)
+
+ f2 = mul2 >> add3
+ assert_kind_of Proc, f2
+ assert_equal 13, f2.call(5)
+end
+
assert('mrb_proc_new_cfunc_with_env') do
ProcExtTest.mrb_proc_new_cfunc_with_env(:test)
ProcExtTest.mrb_proc_new_cfunc_with_env(:mruby)