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.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/lib/option.rb +18 -0
  3. data/spec/option_spec.rb +12 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- Yzk4ZDgwZmExMjEyMzgzMjg3NWRjZTc2ZjA2NmU2MTcwMjhkMDQwMA==
4
+ YWZiZTk0N2M1NTg1MjUxNjY2ODNlNWJhMDU4NjkyYTQzMzUwZTQ5Ng==
5
5
  data.tar.gz: !binary |-
6
- ZDk3Y2YwOTA4ZTE2ZDVjMThjZjU2YTE0NjFmYTVjZjBkZjM3NjllZQ==
6
+ Nzc1ZjRlMjM0YzYxZTcyNzcxZGIxNmNlODE3MjkxN2ZkMmZjZDJhOQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2Y3ODVkMDgyMWNhZjBjOTlkZjc2ZGNmMWQ2MDMyMDQ1YThkNjMzNzNlZThh
10
- MTAyZTYzMDFmODdkMGZhNzI2OTNkMmU1ZTI1MjQ1ZmU5NjFkYWJjYTRkOGNl
11
- MGY3NzUyOTk2NTVhOWRkZjIyMDFmNzE0ZjM1MWE0OWFjMWE5ZDU=
9
+ MDAyYTdjNDMwNjU0MmIwOGVkYjZkNjA5ODdjNWRkODQzZjJjNmViYzM3OTAy
10
+ NDEyMTgzYTc4YTJmZDYxMDdlYzg2MjBiNTMyNGZkNTJkMjhiOGEwNGI1Yzc4
11
+ NTliZTZjNzkxZTQ0N2U2MTk1NmNlZGY4N2MxYjY2MTQ0MGRmNGU=
12
12
  data.tar.gz: !binary |-
13
- Yzg2MDY4OGI0MDNmYzU1MzU1YzE1MjNhYjdkYTI4YzdiZDBiNzlhN2NiMDI3
14
- ZDZkZTJkZWI3YjQ1M2EyMmY5MWM3NzY1ZTUzYzYxZTdhMWVhMGI5MjgyYjA0
15
- ODU2Yjk2ZTgyOTVkOGNlNzFmOTRjYTczYWJjYzRjZmE1M2MyMWQ=
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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: totally_lazy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raymond Barlow