totally_lazy 0.1.20 → 0.1.21
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 +12 -4
- data/spec/option_spec.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
Yzk4ZDgwZmExMjEyMzgzMjg3NWRjZTc2ZjA2NmU2MTcwMjhkMDQwMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDk3Y2YwOTA4ZTE2ZDVjMThjZjU2YTE0NjFmYTVjZjBkZjM3NjllZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2Y3ODVkMDgyMWNhZjBjOTlkZjc2ZGNmMWQ2MDMyMDQ1YThkNjMzNzNlZThh
|
10
|
+
MTAyZTYzMDFmODdkMGZhNzI2OTNkMmU1ZTI1MjQ1ZmU5NjFkYWJjYTRkOGNl
|
11
|
+
MGY3NzUyOTk2NTVhOWRkZjIyMDFmNzE0ZjM1MWE0OWFjMWE5ZDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Yzg2MDY4OGI0MDNmYzU1MzU1YzE1MjNhYjdkYTI4YzdiZDBiNzlhN2NiMDI3
|
14
|
+
ZDZkZTJkZWI3YjQ1M2EyMmY5MWM3NzY1ZTUzYzYxZTdhMWVhMGI5MjgyYjA0
|
15
|
+
ODU2Yjk2ZTgyOTVkOGNlNzFmOTRjYTczYWJjYzRjZmE1M2MyMWQ=
|
data/lib/option.rb
CHANGED
@@ -26,6 +26,10 @@ module Option
|
|
26
26
|
exists?(block_given? ? ->(value) { block_pred.call(value) } : fn_pred)
|
27
27
|
end
|
28
28
|
|
29
|
+
def flatten
|
30
|
+
flat_map(identity)
|
31
|
+
end
|
32
|
+
|
29
33
|
class Some < Option
|
30
34
|
include Comparable
|
31
35
|
attr_reader :value
|
@@ -60,14 +64,14 @@ module Option
|
|
60
64
|
|
61
65
|
alias fold_left fold
|
62
66
|
|
63
|
-
def flatten
|
64
|
-
flat_map(identity)
|
65
|
-
end
|
66
|
-
|
67
67
|
def is_empty?
|
68
68
|
false
|
69
69
|
end
|
70
70
|
|
71
|
+
def size
|
72
|
+
1
|
73
|
+
end
|
74
|
+
|
71
75
|
def enumerator
|
72
76
|
Enumerator.new { |y|
|
73
77
|
y << @value
|
@@ -115,6 +119,10 @@ module Option
|
|
115
119
|
|
116
120
|
alias fold_left fold
|
117
121
|
|
122
|
+
def size
|
123
|
+
0
|
124
|
+
end
|
125
|
+
|
118
126
|
def enumerator
|
119
127
|
Enumerator.new { |y|
|
120
128
|
raise StopIteration.new
|
data/spec/option_spec.rb
CHANGED
@@ -55,6 +55,12 @@ describe 'Option' do
|
|
55
55
|
it 'should support flatten' do
|
56
56
|
expect(some(some(1)).flatten).to eq(some(1))
|
57
57
|
expect(some(none).flatten).to eq(none)
|
58
|
+
expect(none.flatten).to eq(none)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should support size' do
|
62
|
+
expect(some(1).size).to eq(1)
|
63
|
+
expect(none.size).to eq(0)
|
58
64
|
end
|
59
65
|
|
60
66
|
it 'should raise exception if you try to use both lambda and block' do
|