File tree Expand file tree Collapse file tree 5 files changed +41
-20
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 5 files changed +41
-20
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Compatibility:
10
10
* Added ` Kernel#then ` (#1703 ).
11
11
* ` FFI::Struct#[]= ` is now supported for inline character arrays.
12
12
* ` blocking: true ` is now supported for ` FFI::Library#attach_function ` .
13
+ * Implemented ` Proc#>> ` and ` #<< ` (#1688 ).
13
14
14
15
Changes:
15
16
Original file line number Diff line number Diff line change @@ -44,6 +44,14 @@ def double.call(n); n * 2; end
44
44
45
45
( inc << mul ) . call ( 2 , 3 ) . should == 7
46
46
end
47
+
48
+ it "passes blocks to the second proc" do
49
+ ScratchPad . record [ ]
50
+ one = proc { |&arg | arg . call :one if arg }
51
+ two = proc { |&arg | arg . call :two if arg }
52
+ ( one << two ) . call { |x | ScratchPad << x }
53
+ ScratchPad . recorded . should == [ :two ]
54
+ end
47
55
end
48
56
end
49
57
@@ -89,6 +97,14 @@ def double.call(n); n * 2; end
89
97
90
98
( mul >> inc ) . call ( 2 , 3 ) . should == 7
91
99
end
100
+
101
+ it "passes blocks to the first proc" do
102
+ ScratchPad . record [ ]
103
+ one = proc { |&arg | arg . call :one if arg }
104
+ two = proc { |&arg | arg . call :two if arg }
105
+ ( one >> two ) . call { |x | ScratchPad << x }
106
+ ScratchPad . recorded . should == [ :one ]
107
+ end
92
108
end
93
109
end
94
110
end
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -103,4 +103,28 @@ def to_s
103
103
def to_proc
104
104
self
105
105
end
106
+
107
+ def >>( other )
108
+ if other . respond_to? ( :lambda? ) && other . lambda?
109
+ -> ( *args , &block ) do
110
+ other . call ( call ( *args , &block ) )
111
+ end
112
+ else
113
+ proc do |*args , &block |
114
+ other . call ( call ( *args , &block ) )
115
+ end
116
+ end
117
+ end
118
+
119
+ def <<( other )
120
+ if other . respond_to? ( :lambda? ) && other . lambda?
121
+ -> ( *args , &block ) do
122
+ call ( other . call ( *args , &block ) )
123
+ end
124
+ else
125
+ proc do |*args , &block |
126
+ call ( other . call ( *args , &block ) )
127
+ end
128
+ end
129
+ end
106
130
end
Original file line number Diff line number Diff line change 9
9
exclude :test_proc_args_opt_single , "needs investigation"
10
10
exclude :test_to_s , "needs investigation"
11
11
exclude :test_binding , "needs investigation"
12
- exclude :test_compose , "needs investigation"
13
- exclude :test_compose_with_block , "needs investigation"
14
- exclude :test_compose_with_callable , "needs investigation"
15
- exclude :test_compose_with_lambda , "needs investigation"
16
- exclude :test_compose_with_method , "needs investigation"
17
- exclude :test_compose_with_multiple_args , "needs investigation"
18
12
exclude :test_curry_given_blocks , "needs investigation"
19
13
exclude :test_curry_lambda_splat , "needs investigation"
20
14
exclude :test_dup_clone , "needs investigation"
You can’t perform that action at this time.
0 commit comments