totally_lazy 0.1.23 → 0.1.24
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 +8 -8
- data/lib/totally_lazy/option.rb +8 -0
- data/lib/totally_lazy/sequence.rb +0 -1
- data/spec/option_spec.rb +8 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDYzZWI5MTUyYTE0ZDkwNjc4YWUzYzRkYTJhMTRiZmRiNjkyMjczNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmY4ZmI5OTIwNTk2ODNmYTA2OGU5Yjc3YmIyZjM1MjJiMThmMjE1ZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YWQ0MGNkM2RmYjhmZDkxOWM1MDM3ZDg2Y2E1ZjI4ZTNiNmQxODM1MzlhY2Vh
|
10
|
+
OTM5M2IyYmM5M2JjNGIxM2VjNDk3YmNkNWJlMzJmMGVjN2I1NWUwZDc1OGEz
|
11
|
+
MDBlNWRhNzY4M2ZmODViYThjYjI2YjNlNTAyMzg3ZmQ2YzU0NjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODIwNjgyZTQzMWE3MmM2OWViY2I0MTMxODkzNjBkZjcwODMwNmZiNDRjOTM4
|
14
|
+
Y2UwODQ4ZmZkZTRlYTg2MjIwYWE5MmU1OWRlNTVjNGU3MDZmZTI1YTE5ZDQ5
|
15
|
+
MjQxOTBiMjczYTYyODhiMGZiZTNlNTNjZDk4NGIxNmRkY2UxMmU=
|
data/lib/totally_lazy/option.rb
CHANGED
@@ -109,6 +109,10 @@ class Some < Option
|
|
109
109
|
|
110
110
|
alias or_else get_or_else
|
111
111
|
|
112
|
+
def get_or_nil
|
113
|
+
get
|
114
|
+
end
|
115
|
+
|
112
116
|
def enumerator
|
113
117
|
Enumerator.new { |y|
|
114
118
|
y << @value
|
@@ -177,6 +181,10 @@ class None < Option
|
|
177
181
|
|
178
182
|
alias or_else get_or_else
|
179
183
|
|
184
|
+
def get_or_nil
|
185
|
+
nil
|
186
|
+
end
|
187
|
+
|
180
188
|
def enumerator
|
181
189
|
Enumerator.new { |y|
|
182
190
|
raise StopIteration.new
|
data/spec/option_spec.rb
CHANGED
@@ -70,7 +70,7 @@ describe 'Option' do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'should support get_or_else with value (aka or_else)' do
|
73
|
-
expect(
|
73
|
+
expect(some(1).get_or_else(2)).to eq(1)
|
74
74
|
expect(some(1).or_else(2)).to eq(1)
|
75
75
|
expect(none.get_or_else(2)).to eq(2)
|
76
76
|
expect(option(1).get_or_else(2)).to eq(1)
|
@@ -86,6 +86,13 @@ describe 'Option' do
|
|
86
86
|
expect { option(nil).get_or_else(call_raises(RuntimeError.new)) }.to raise_error(RuntimeError)
|
87
87
|
end
|
88
88
|
|
89
|
+
it 'should support get_or_nil' do
|
90
|
+
expect(some(1).get_or_nil).to eq(1)
|
91
|
+
expect(none.get_or_nil).to eq(nil)
|
92
|
+
expect(option(1).get_or_nil).to eq(1)
|
93
|
+
expect(option(nil).get_or_nil).to eq(nil)
|
94
|
+
end
|
95
|
+
|
89
96
|
it 'should raise exception if you try to use both lambda and block' do
|
90
97
|
expect { some(1).exists?(->(a) { a == 1 }) { |b| b == 2 } }.to raise_error(RuntimeError)
|
91
98
|
expect { none.exists?(->(a) { a == 1 }) { |b| b == 2 } }.to raise_error(RuntimeError)
|