fear 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -60
- data/.travis.yml +8 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile +5 -3
- data/Gemfile.lock +18 -20
- data/README.md +28 -14
- data/Rakefile +61 -60
- data/examples/pattern_extracting.rb +8 -6
- data/examples/pattern_matching_binary_tree_set.rb +4 -2
- data/examples/pattern_matching_number_in_words.rb +46 -42
- data/fear.gemspec +29 -27
- data/lib/fear.rb +44 -37
- data/lib/fear/await.rb +33 -0
- data/lib/fear/awaitable.rb +28 -0
- data/lib/fear/either.rb +2 -0
- data/lib/fear/either_api.rb +2 -0
- data/lib/fear/either_pattern_match.rb +2 -0
- data/lib/fear/empty_partial_function.rb +3 -1
- data/lib/fear/extractor.rb +30 -28
- data/lib/fear/extractor/anonymous_array_splat_matcher.rb +2 -0
- data/lib/fear/extractor/any_matcher.rb +2 -0
- data/lib/fear/extractor/array_head_matcher.rb +2 -0
- data/lib/fear/extractor/array_matcher.rb +2 -0
- data/lib/fear/extractor/array_splat_matcher.rb +2 -0
- data/lib/fear/extractor/empty_list_matcher.rb +2 -0
- data/lib/fear/extractor/extractor_matcher.rb +5 -3
- data/lib/fear/extractor/grammar.rb +5 -3
- data/lib/fear/extractor/identifier_matcher.rb +2 -0
- data/lib/fear/extractor/matcher.rb +5 -3
- data/lib/fear/extractor/matcher/and.rb +3 -1
- data/lib/fear/extractor/named_array_splat_matcher.rb +2 -0
- data/lib/fear/extractor/pattern.rb +7 -5
- data/lib/fear/extractor/typed_identifier_matcher.rb +2 -0
- data/lib/fear/extractor/value_matcher.rb +2 -0
- data/lib/fear/extractor_api.rb +2 -0
- data/lib/fear/failure.rb +2 -0
- data/lib/fear/failure_pattern_match.rb +2 -0
- data/lib/fear/for.rb +4 -2
- data/lib/fear/for_api.rb +3 -1
- data/lib/fear/future.rb +141 -64
- data/lib/fear/future_api.rb +2 -0
- data/lib/fear/left.rb +3 -1
- data/lib/fear/left_pattern_match.rb +2 -0
- data/lib/fear/none.rb +4 -2
- data/lib/fear/none_pattern_match.rb +2 -0
- data/lib/fear/option.rb +3 -1
- data/lib/fear/option_api.rb +2 -0
- data/lib/fear/option_pattern_match.rb +2 -0
- data/lib/fear/partial_function.rb +10 -8
- data/lib/fear/partial_function/and_then.rb +4 -2
- data/lib/fear/partial_function/any.rb +2 -0
- data/lib/fear/partial_function/combined.rb +3 -1
- data/lib/fear/partial_function/empty.rb +2 -0
- data/lib/fear/partial_function/guard.rb +7 -5
- data/lib/fear/partial_function/guard/and.rb +2 -0
- data/lib/fear/partial_function/guard/and3.rb +2 -0
- data/lib/fear/partial_function/guard/or.rb +2 -0
- data/lib/fear/partial_function/lifted.rb +2 -0
- data/lib/fear/partial_function/or_else.rb +3 -1
- data/lib/fear/partial_function_class.rb +3 -1
- data/lib/fear/pattern_match.rb +3 -1
- data/lib/fear/pattern_matching_api.rb +3 -1
- data/lib/fear/promise.rb +11 -3
- data/lib/fear/right.rb +3 -1
- data/lib/fear/right_biased.rb +4 -2
- data/lib/fear/right_pattern_match.rb +2 -0
- data/lib/fear/some.rb +2 -0
- data/lib/fear/some_pattern_match.rb +2 -0
- data/lib/fear/struct.rb +235 -0
- data/lib/fear/success.rb +2 -0
- data/lib/fear/success_pattern_match.rb +2 -0
- data/lib/fear/try.rb +2 -0
- data/lib/fear/try_api.rb +2 -0
- data/lib/fear/try_pattern_match.rb +2 -0
- data/lib/fear/unit.rb +6 -2
- data/lib/fear/utils.rb +4 -2
- data/lib/fear/version.rb +4 -1
- data/spec/fear/done_spec.rb +7 -5
- data/spec/fear/either/mixin_spec.rb +4 -2
- data/spec/fear/either_pattern_match_spec.rb +10 -8
- data/spec/fear/extractor/array_matcher_spec.rb +65 -63
- data/spec/fear/extractor/extractor_matcher_spec.rb +64 -62
- data/spec/fear/extractor/grammar_array_spec.rb +5 -3
- data/spec/fear/extractor/identified_matcher_spec.rb +18 -16
- data/spec/fear/extractor/identifier_matcher_spec.rb +26 -24
- data/spec/fear/extractor/pattern_spec.rb +17 -15
- data/spec/fear/extractor/typed_identifier_matcher_spec.rb +23 -21
- data/spec/fear/extractor/value_matcher_number_spec.rb +29 -27
- data/spec/fear/extractor/value_matcher_string_spec.rb +27 -25
- data/spec/fear/extractor/value_matcher_symbol_spec.rb +24 -22
- data/spec/fear/extractor_api_spec.rb +70 -68
- data/spec/fear/extractor_spec.rb +23 -21
- data/spec/fear/failure_spec.rb +59 -57
- data/spec/fear/for_spec.rb +19 -17
- data/spec/fear/future_spec.rb +456 -240
- data/spec/fear/guard_spec.rb +26 -24
- data/spec/fear/left_spec.rb +60 -58
- data/spec/fear/none_spec.rb +36 -34
- data/spec/fear/option/mixin_spec.rb +9 -7
- data/spec/fear/option_pattern_match_spec.rb +10 -8
- data/spec/fear/partial_function/empty_spec.rb +12 -10
- data/spec/fear/partial_function_and_then_spec.rb +39 -37
- data/spec/fear/partial_function_composition_spec.rb +46 -44
- data/spec/fear/partial_function_or_else_spec.rb +92 -90
- data/spec/fear/partial_function_spec.rb +46 -44
- data/spec/fear/pattern_match_spec.rb +31 -29
- data/spec/fear/promise_spec.rb +19 -17
- data/spec/fear/right_biased/left.rb +28 -26
- data/spec/fear/right_biased/right.rb +51 -49
- data/spec/fear/right_spec.rb +58 -56
- data/spec/fear/some_spec.rb +30 -28
- data/spec/fear/success_spec.rb +50 -48
- data/spec/fear/try/mixin_spec.rb +5 -3
- data/spec/fear/try_pattern_match_spec.rb +10 -8
- data/spec/fear/utils_spec.rb +16 -14
- data/spec/spec_helper.rb +7 -5
- data/spec/struct_spec.rb +226 -0
- metadata +18 -13
data/spec/fear/extractor_spec.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Fear::Extractor do
|
2
|
-
describe
|
3
|
-
Foo = Struct.new(:v1, :v2)
|
4
|
+
describe ".register_extractor" do
|
5
|
+
Foo = ::Struct.new(:v1, :v2)
|
4
6
|
let(:matcher) do
|
5
7
|
Fear.matcher do |m|
|
6
|
-
m.case(Fear[
|
7
|
-
m.case(Fear[
|
8
|
-
m.else {
|
8
|
+
m.case(Fear["Foo(43, second : Integer)"]) { |second| "43 and #{second}" }
|
9
|
+
m.case(Fear["Foo(42, second : Integer)"]) { |second| "42 and #{second}" }
|
10
|
+
m.else { "no match" }
|
9
11
|
end
|
10
12
|
end
|
11
13
|
|
@@ -13,46 +15,46 @@ RSpec.describe Fear::Extractor do
|
|
13
15
|
Fear.case(Foo) { |foo| [foo.v1, foo.v2] }.lift
|
14
16
|
end
|
15
17
|
|
16
|
-
context
|
17
|
-
it
|
18
|
+
context "extractor not registered" do
|
19
|
+
it "raise Fear::Extractor::ExtractorNotFound" do
|
18
20
|
expect do
|
19
|
-
described_class.find_extractor(
|
21
|
+
described_class.find_extractor("UnknownExtractor")
|
20
22
|
end.to raise_error(Fear::Extractor::ExtractorNotFound)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
|
24
|
-
context
|
25
|
-
let(:extractor) { ->(*) { Fear.some(
|
26
|
+
context "register by name" do
|
27
|
+
let(:extractor) { ->(*) { Fear.some("matched") } }
|
26
28
|
|
27
29
|
before do
|
28
30
|
described_class.register_extractor(
|
29
|
-
|
30
|
-
|
31
|
+
"ExtractorRegisteredByName",
|
32
|
+
"ExtractorRegisteredByName2",
|
31
33
|
extractor,
|
32
34
|
)
|
33
35
|
end
|
34
36
|
|
35
|
-
it
|
36
|
-
expect(described_class.find_extractor(
|
37
|
-
expect(described_class.find_extractor(
|
37
|
+
it "returns extractor" do
|
38
|
+
expect(described_class.find_extractor("ExtractorRegisteredByName")).to eq(extractor)
|
39
|
+
expect(described_class.find_extractor("ExtractorRegisteredByName2")).to eq(extractor)
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
context
|
42
|
-
let(:extractor) { ->(*) { Fear.some(
|
43
|
+
context "register by class" do
|
44
|
+
let(:extractor) { ->(*) { Fear.some("matched") } }
|
43
45
|
ExtractorRegisteredByClass = Class.new
|
44
46
|
|
45
47
|
before do
|
46
48
|
described_class.register_extractor(
|
47
49
|
ExtractorRegisteredByClass,
|
48
|
-
|
50
|
+
"ExtractorRegisteredByClass2",
|
49
51
|
extractor,
|
50
52
|
)
|
51
53
|
end
|
52
54
|
|
53
|
-
it
|
54
|
-
expect(described_class.find_extractor(
|
55
|
-
expect(described_class.find_extractor(
|
55
|
+
it "returns extractor" do
|
56
|
+
expect(described_class.find_extractor("ExtractorRegisteredByClass")).to eq(extractor)
|
57
|
+
expect(described_class.find_extractor("ExtractorRegisteredByClass2")).to eq(extractor)
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
data/spec/fear/failure_spec.rb
CHANGED
@@ -1,155 +1,157 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Fear::Failure do
|
2
|
-
let(:exception) { RuntimeError.new(
|
4
|
+
let(:exception) { RuntimeError.new("error") }
|
3
5
|
let(:failure) { Fear.failure(exception) }
|
4
6
|
|
5
7
|
it_behaves_like Fear::RightBiased::Left do
|
6
8
|
let(:left) { failure }
|
7
9
|
end
|
8
10
|
|
9
|
-
describe
|
11
|
+
describe "#exception" do
|
10
12
|
subject { failure.exception }
|
11
13
|
it { is_expected.to eq(exception) }
|
12
14
|
end
|
13
15
|
|
14
|
-
describe
|
16
|
+
describe "#success?" do
|
15
17
|
subject { failure }
|
16
18
|
it { is_expected.not_to be_success }
|
17
19
|
end
|
18
20
|
|
19
|
-
describe
|
21
|
+
describe "#failure?" do
|
20
22
|
subject { failure }
|
21
23
|
it { is_expected.to be_failure }
|
22
24
|
end
|
23
25
|
|
24
|
-
describe
|
26
|
+
describe "#get" do
|
25
27
|
subject { proc { failure.get } }
|
26
|
-
it { is_expected.to raise_error(RuntimeError,
|
28
|
+
it { is_expected.to raise_error(RuntimeError, "error") }
|
27
29
|
end
|
28
30
|
|
29
|
-
describe
|
30
|
-
context
|
31
|
-
subject { failure.or_else { Fear::Success.new(
|
32
|
-
it { is_expected.to eq(Fear::Success.new(
|
31
|
+
describe "#or_else" do
|
32
|
+
context "default does not fail" do
|
33
|
+
subject { failure.or_else { Fear::Success.new("value") } }
|
34
|
+
it { is_expected.to eq(Fear::Success.new("value")) }
|
33
35
|
end
|
34
36
|
|
35
|
-
context
|
36
|
-
subject(:or_else) { failure.or_else { raise
|
37
|
+
context "default fails with error" do
|
38
|
+
subject(:or_else) { failure.or_else { raise "unexpected error" } }
|
37
39
|
it { is_expected.to be_kind_of(described_class) }
|
38
|
-
it { expect { or_else.get }.to raise_error(RuntimeError,
|
40
|
+
it { expect { or_else.get }.to raise_error(RuntimeError, "unexpected error") }
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
|
-
describe
|
44
|
+
describe "#flatten" do
|
43
45
|
subject { failure.flatten }
|
44
46
|
it { is_expected.to eq(failure) }
|
45
47
|
end
|
46
48
|
|
47
|
-
describe
|
48
|
-
subject { failure.select { |v| v ==
|
49
|
+
describe "#select" do
|
50
|
+
subject { failure.select { |v| v == "value" } }
|
49
51
|
it { is_expected.to eq(failure) }
|
50
52
|
end
|
51
53
|
|
52
|
-
context
|
53
|
-
context
|
54
|
+
context "#recover_with" do
|
55
|
+
context "block matches the error and does not fail" do
|
54
56
|
subject do
|
55
57
|
failure.recover_with do |m|
|
56
58
|
m.case(RuntimeError) { |error| Fear.success(error.message) }
|
57
59
|
end
|
58
60
|
end
|
59
61
|
|
60
|
-
it
|
61
|
-
is_expected.to eq(Fear::Success.new(
|
62
|
+
it "returns result of evaluation of the block against the error" do
|
63
|
+
is_expected.to eq(Fear::Success.new("error"))
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
65
|
-
context
|
67
|
+
context "block does not match the error" do
|
66
68
|
subject do
|
67
69
|
failure.recover_with do |m|
|
68
70
|
m.case(ZeroDivisionError) { Fear.success(0) }
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
72
|
-
it
|
74
|
+
it "returns the same failure" do
|
73
75
|
is_expected.to eq(failure)
|
74
76
|
end
|
75
77
|
end
|
76
78
|
|
77
|
-
context
|
78
|
-
subject(:recover_with) { failure.recover_with { raise
|
79
|
+
context "block fails" do
|
80
|
+
subject(:recover_with) { failure.recover_with { raise "unexpected error" } }
|
79
81
|
|
80
82
|
it { is_expected.to be_kind_of(described_class) }
|
81
|
-
it { expect { recover_with.get }.to raise_error(RuntimeError,
|
83
|
+
it { expect { recover_with.get }.to raise_error(RuntimeError, "unexpected error") }
|
82
84
|
end
|
83
85
|
end
|
84
86
|
|
85
|
-
context
|
86
|
-
context
|
87
|
+
context "#recover" do
|
88
|
+
context "block matches the error and does not fail" do
|
87
89
|
subject do
|
88
90
|
failure.recover do |m|
|
89
91
|
m.case(RuntimeError, &:message)
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
93
|
-
it
|
94
|
-
is_expected.to eq(Fear.success(
|
95
|
+
it "returns Success of evaluation of the block against the error" do
|
96
|
+
is_expected.to eq(Fear.success("error"))
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
98
|
-
context
|
100
|
+
context "block does not match the error" do
|
99
101
|
subject do
|
100
102
|
failure.recover do |m|
|
101
103
|
m.case(ZeroDivisionError, &:message)
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
105
|
-
it
|
107
|
+
it "returns the same failure" do
|
106
108
|
is_expected.to eq(failure)
|
107
109
|
end
|
108
110
|
end
|
109
111
|
|
110
|
-
context
|
112
|
+
context "block fails" do
|
111
113
|
subject(:recover) do
|
112
114
|
failure.recover do
|
113
|
-
raise
|
115
|
+
raise "unexpected error"
|
114
116
|
end
|
115
117
|
end
|
116
118
|
|
117
119
|
it { is_expected.to be_kind_of(described_class) }
|
118
|
-
it { expect { recover.get }.to raise_error(RuntimeError,
|
120
|
+
it { expect { recover.get }.to raise_error(RuntimeError, "unexpected error") }
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
122
|
-
describe
|
124
|
+
describe "#to_either" do
|
123
125
|
subject { failure.to_either }
|
124
126
|
it { is_expected.to eq(Fear.left(exception)) }
|
125
127
|
end
|
126
128
|
|
127
|
-
describe
|
129
|
+
describe "#===" do
|
128
130
|
subject { match === failure }
|
129
131
|
|
130
|
-
context
|
132
|
+
context "matches erectly" do
|
131
133
|
let(:match) { Fear.failure(exception) }
|
132
134
|
it { is_expected.to eq(true) }
|
133
135
|
end
|
134
136
|
|
135
|
-
context
|
137
|
+
context "value does not match" do
|
136
138
|
let(:match) { Fear.failure(ArgumentError.new) }
|
137
139
|
it { is_expected.to eq(false) }
|
138
140
|
end
|
139
141
|
|
140
|
-
context
|
142
|
+
context "matches by class" do
|
141
143
|
let(:match) { Fear.failure(RuntimeError) }
|
142
144
|
it { is_expected.to eq(true) }
|
143
145
|
end
|
144
146
|
|
145
|
-
context
|
147
|
+
context "does not matches by class" do
|
146
148
|
let(:match) { Fear.failure(ArgumentError) }
|
147
149
|
it { is_expected.to eq(false) }
|
148
150
|
end
|
149
151
|
end
|
150
152
|
|
151
|
-
describe
|
152
|
-
context
|
153
|
+
describe "#match" do
|
154
|
+
context "matched" do
|
153
155
|
subject do
|
154
156
|
failure.match do |m|
|
155
157
|
m.failure(->(x) { x.message.length < 2 }) { |x| "Error: #{x}" }
|
@@ -158,15 +160,15 @@ RSpec.describe Fear::Failure do
|
|
158
160
|
end
|
159
161
|
end
|
160
162
|
|
161
|
-
it { is_expected.to eq(
|
163
|
+
it { is_expected.to eq("Error: error") }
|
162
164
|
end
|
163
165
|
|
164
|
-
context
|
166
|
+
context "nothing matched and no else given" do
|
165
167
|
subject do
|
166
168
|
proc do
|
167
169
|
failure.match do |m|
|
168
170
|
m.failure(->(x) { x.message.length < 2 }) { |x| "Error: #{x}" }
|
169
|
-
m.success {
|
171
|
+
m.success { "noop" }
|
170
172
|
end
|
171
173
|
end
|
172
174
|
end
|
@@ -174,7 +176,7 @@ RSpec.describe Fear::Failure do
|
|
174
176
|
it { is_expected.to raise_error(Fear::MatchError) }
|
175
177
|
end
|
176
178
|
|
177
|
-
context
|
179
|
+
context "nothing matched and else given" do
|
178
180
|
subject do
|
179
181
|
failure.match do |m|
|
180
182
|
m.failure(->(x) { x.message.length < 2 }) { |x| "Error: #{x}" }
|
@@ -186,31 +188,31 @@ RSpec.describe Fear::Failure do
|
|
186
188
|
end
|
187
189
|
end
|
188
190
|
|
189
|
-
describe
|
191
|
+
describe "#to_s" do
|
190
192
|
subject { failure.to_s }
|
191
193
|
|
192
|
-
it { is_expected.to eq(
|
194
|
+
it { is_expected.to eq("#<Fear::Failure exception=#<RuntimeError: error>>") }
|
193
195
|
end
|
194
196
|
|
195
|
-
describe
|
196
|
-
subject { Fear.xcase(
|
197
|
+
describe "pattern matching" do
|
198
|
+
subject { Fear.xcase("Failure(v : ArgumentError)") { "matched" }.call_or_else(var) { "nothing" } }
|
197
199
|
|
198
|
-
context
|
200
|
+
context "failure of ArgumentError" do
|
199
201
|
let(:var) { Fear.failure(ArgumentError.new) }
|
200
202
|
|
201
|
-
it { is_expected.to eq(
|
203
|
+
it { is_expected.to eq("matched") }
|
202
204
|
end
|
203
205
|
|
204
|
-
context
|
206
|
+
context "failure of RuntimeError" do
|
205
207
|
let(:var) { Fear.failure(RuntimeError.new) }
|
206
208
|
|
207
|
-
it { is_expected.to eq(
|
209
|
+
it { is_expected.to eq("nothing") }
|
208
210
|
end
|
209
211
|
|
210
|
-
context
|
211
|
-
let(:var) {
|
212
|
+
context "not failure" do
|
213
|
+
let(:var) { "42" }
|
212
214
|
|
213
|
-
it { is_expected.to eq(
|
215
|
+
it { is_expected.to eq("nothing") }
|
214
216
|
end
|
215
217
|
end
|
216
218
|
end
|
data/spec/fear/for_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
RSpec.describe Fear::For do
|
2
|
-
context
|
3
|
-
context
|
4
|
+
context "unary" do
|
5
|
+
context "Some" do
|
4
6
|
subject do
|
5
7
|
Fear.for(Fear.some(2)) { |a| a * 2 }
|
6
8
|
end
|
@@ -8,7 +10,7 @@ RSpec.describe Fear::For do
|
|
8
10
|
it { is_expected.to eq(Fear.some(4)) }
|
9
11
|
end
|
10
12
|
|
11
|
-
context
|
13
|
+
context "None" do
|
12
14
|
subject do
|
13
15
|
Fear.for(Fear.none) { |a| a * 2 }
|
14
16
|
end
|
@@ -17,7 +19,7 @@ RSpec.describe Fear::For do
|
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
context
|
22
|
+
context "arrays" do
|
21
23
|
subject do
|
22
24
|
Fear.for([1, 2], [2, 3], [3, 4]) do |a, b, c|
|
23
25
|
a * b * c
|
@@ -27,14 +29,14 @@ RSpec.describe Fear::For do
|
|
27
29
|
it { is_expected.to eq([6, 8, 9, 12, 12, 16, 18, 24]) }
|
28
30
|
end
|
29
31
|
|
30
|
-
context
|
32
|
+
context "ternary" do
|
31
33
|
subject do
|
32
34
|
Fear.for(first, second, third) do |a, b, c|
|
33
35
|
a * b * c
|
34
36
|
end
|
35
37
|
end
|
36
38
|
|
37
|
-
context
|
39
|
+
context "all Same" do
|
38
40
|
let(:first) { Fear.some(2) }
|
39
41
|
let(:second) { Fear.some(3) }
|
40
42
|
let(:third) { Fear.some(4) }
|
@@ -42,7 +44,7 @@ RSpec.describe Fear::For do
|
|
42
44
|
it { is_expected.to eq(Fear.some(24)) }
|
43
45
|
end
|
44
46
|
|
45
|
-
context
|
47
|
+
context "first is None" do
|
46
48
|
let(:first) { Fear.none }
|
47
49
|
let(:second) { Fear.some(3) }
|
48
50
|
let(:third) { Fear.some(4) }
|
@@ -50,7 +52,7 @@ RSpec.describe Fear::For do
|
|
50
52
|
it { is_expected.to eq(Fear.none) }
|
51
53
|
end
|
52
54
|
|
53
|
-
context
|
55
|
+
context "second is None" do
|
54
56
|
let(:first) { Fear.some(2) }
|
55
57
|
let(:second) { Fear.none }
|
56
58
|
let(:third) { Fear.some(4) }
|
@@ -58,7 +60,7 @@ RSpec.describe Fear::For do
|
|
58
60
|
it { is_expected.to eq(Fear.none) }
|
59
61
|
end
|
60
62
|
|
61
|
-
context
|
63
|
+
context "last is None" do
|
62
64
|
let(:first) { Fear.some(2) }
|
63
65
|
let(:second) { Fear.some(3) }
|
64
66
|
let(:third) { Fear.none }
|
@@ -66,7 +68,7 @@ RSpec.describe Fear::For do
|
|
66
68
|
it { is_expected.to eq(Fear.none) }
|
67
69
|
end
|
68
70
|
|
69
|
-
context
|
71
|
+
context "all Same in lambdas" do
|
70
72
|
let(:first) { proc { Fear.some(2) } }
|
71
73
|
let(:second) { proc { Fear.some(3) } }
|
72
74
|
let(:third) { proc { Fear.some(4) } }
|
@@ -74,28 +76,28 @@ RSpec.describe Fear::For do
|
|
74
76
|
it { is_expected.to eq(Fear.some(24)) }
|
75
77
|
end
|
76
78
|
|
77
|
-
context
|
79
|
+
context "first is None in lambda, second is failure in lambda" do
|
78
80
|
let(:first) { proc { Fear.none } }
|
79
|
-
let(:second) { proc { raise
|
81
|
+
let(:second) { proc { raise "kaboom" } }
|
80
82
|
let(:third) { proc {} }
|
81
83
|
|
82
|
-
it
|
84
|
+
it "returns None without evaluating second and third" do
|
83
85
|
is_expected.to eq(Fear.none)
|
84
86
|
end
|
85
87
|
end
|
86
88
|
|
87
|
-
context
|
89
|
+
context "second is None in lambda, third is failure in lambda" do
|
88
90
|
let(:first) { Fear.some(2) }
|
89
91
|
let(:second) { proc { Fear.none } }
|
90
|
-
let(:third) { proc { raise
|
92
|
+
let(:third) { proc { raise "kaboom" } }
|
91
93
|
|
92
|
-
it
|
94
|
+
it "returns None without evaluating third" do
|
93
95
|
is_expected.to eq(Fear.none)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
98
|
-
context
|
100
|
+
context "refer to previous variable from lambda" do
|
99
101
|
subject do
|
100
102
|
Fear.for(first, second, third) do |_, b, c|
|
101
103
|
b * c
|