totally_lazy 0.1.24 → 0.1.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/totally_lazy/option.rb +11 -0
- data/spec/option_spec.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NTg4NmIzMmQ3NDlhYmU5ZWY1MzY2MjlmNTNkZjJhOTFmMWJjNDViMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZjZjZjFjY2NiNzQ4ZWI0NjVjOTczMzE3NTQ5YWI5ZTJmNTU2MDY0Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjhhY2YzNTY2ZWMyZmQyZDA0OWU5NmM0NjMxZWE3OGFiNGNjOTZiMzdlN2Vm
|
10
|
+
OWNmZDU4NjI2MGQ0MWQyNjI3YTExZmY2NGQyODhlZDhlN2RkNzVmZTY5OGVj
|
11
|
+
N2I1YzVlODVjMWJkYmRiYTliYTU5NDE0Yjk0ZWM2M2Q3NDFmOTE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MjcwMTY3OWIxNjBlNjk5ZTY1YTAxODM1ZWI1MzVlYmJjZGQ1ZDk0Mzg0YWQ0
|
14
|
+
MGQ4ZWI2OTkyMDA4YWUwYThlZWY2YmMwNjhjYzljZDEyNGQ0ZjgxOGY5Y2Qz
|
15
|
+
ZTZiMjZkMzBhODcyZjk1NzQ1ZGZhNGEwMmZiOTQ1YTVhZWE4M2U=
|
data/lib/totally_lazy/option.rb
CHANGED
@@ -113,6 +113,12 @@ class Some < Option
|
|
113
113
|
get
|
114
114
|
end
|
115
115
|
|
116
|
+
def get_or_raise(error)
|
117
|
+
get
|
118
|
+
end
|
119
|
+
|
120
|
+
alias get_or_throw get_or_raise
|
121
|
+
|
116
122
|
def enumerator
|
117
123
|
Enumerator.new { |y|
|
118
124
|
y << @value
|
@@ -185,6 +191,11 @@ class None < Option
|
|
185
191
|
nil
|
186
192
|
end
|
187
193
|
|
194
|
+
def get_or_raise(error)
|
195
|
+
raise error
|
196
|
+
end
|
197
|
+
|
198
|
+
alias get_or_throw get_or_raise
|
188
199
|
def enumerator
|
189
200
|
Enumerator.new { |y|
|
190
201
|
raise StopIteration.new
|
data/spec/option_spec.rb
CHANGED
@@ -93,6 +93,11 @@ describe 'Option' do
|
|
93
93
|
expect(option(nil).get_or_nil).to eq(nil)
|
94
94
|
end
|
95
95
|
|
96
|
+
it 'should support get_or_raise' do
|
97
|
+
expect(some("bob").get_or_raise(RuntimeError.new)).to eq("bob")
|
98
|
+
expect{none.get_or_raise(RuntimeError.new)}.to raise_error(RuntimeError)
|
99
|
+
end
|
100
|
+
|
96
101
|
it 'should raise exception if you try to use both lambda and block' do
|
97
102
|
expect { some(1).exists?(->(a) { a == 1 }) { |b| b == 2 } }.to raise_error(RuntimeError)
|
98
103
|
expect { none.exists?(->(a) { a == 1 }) { |b| b == 2 } }.to raise_error(RuntimeError)
|