totally_lazy 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/option.rb +18 -0
- data/spec/option_spec.rb +12 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YWZiZTk0N2M1NTg1MjUxNjY2ODNlNWJhMDU4NjkyYTQzMzUwZTQ5Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Nzc1ZjRlMjM0YzYxZTcyNzcxZGIxNmNlODE3MjkxN2ZkMmZjZDJhOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDAyYTdjNDMwNjU0MmIwOGVkYjZkNjA5ODdjNWRkODQzZjJjNmViYzM3OTAy
|
10
|
+
NDEyMTgzYTc4YTJmZDYxMDdlYzg2MjBiNTMyNGZkNTJkMjhiOGEwNGI1Yzc4
|
11
|
+
NTliZTZjNzkxZTQ0N2U2MTk1NmNlZGY4N2MxYjY2MTQ0MGRmNGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjlhNjBmNDQ5Yjg4MzQzNTI5OTIwNjBlZTdmYWNmNzQ2YjQyY2MwMGU3Njk5
|
14
|
+
NDY4NjhhMDJiNWQzYTg3MTdmZTFhNGI4NWY1MWFiY2E5ZjQ0MmU0NmM3OGRl
|
15
|
+
N2M0MjdjYzBjZmYwODU4OTY1ZDQ3NDFjYzQzYzM2YjFkYjY3YWE=
|
data/lib/option.rb
CHANGED
@@ -72,6 +72,14 @@ module Option
|
|
72
72
|
1
|
73
73
|
end
|
74
74
|
|
75
|
+
def get
|
76
|
+
@value
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_or_else(value)
|
80
|
+
get
|
81
|
+
end
|
82
|
+
|
75
83
|
def enumerator
|
76
84
|
Enumerator.new { |y|
|
77
85
|
y << @value
|
@@ -123,6 +131,16 @@ module Option
|
|
123
131
|
0
|
124
132
|
end
|
125
133
|
|
134
|
+
def get
|
135
|
+
raise NoSuchElementException.new
|
136
|
+
end
|
137
|
+
|
138
|
+
def get_or_else(value)
|
139
|
+
value
|
140
|
+
end
|
141
|
+
|
142
|
+
alias or_else get_or_else
|
143
|
+
|
126
144
|
def enumerator
|
127
145
|
Enumerator.new { |y|
|
128
146
|
raise StopIteration.new
|
data/spec/option_spec.rb
CHANGED
@@ -63,6 +63,18 @@ describe 'Option' do
|
|
63
63
|
expect(none.size).to eq(0)
|
64
64
|
end
|
65
65
|
|
66
|
+
it 'should support get' do
|
67
|
+
expect(some(1).get).to eq(1)
|
68
|
+
expect{none.get}.to raise_error(NoSuchElementException)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should support get_or_else (aka or_else)' do
|
72
|
+
expect(some(1).get_or_else(2)).to eq(1)
|
73
|
+
expect(none.get_or_else(2)).to eq(2)
|
74
|
+
expect(option(1).get_or_else(2)).to eq(1)
|
75
|
+
expect(option(nil).get_or_else(2)).to eq(2)
|
76
|
+
end
|
77
|
+
|
66
78
|
it 'should raise exception if you try to use both lambda and block' do
|
67
79
|
expect { some(1).exists?(->(a) { a == 1 }) { |b| b == 2 } }.to raise_error(RuntimeError)
|
68
80
|
expect { none.exists?(->(a) { a == 1 }) { |b| b == 2 } }.to raise_error(RuntimeError)
|