totally_lazy 0.0.1 → 0.0.2
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 +4 -4
- data/README.md +4 -2
- data/VERSION +1 -1
- data/lib/option.rb +3 -3
- data/spec/option_spec.rb +8 -5
- data/totally_lazy.gemspec +69 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2bd08beb128d57daef7cb8259b9dd391d77d3f6
|
4
|
+
data.tar.gz: 0436a18ccd3dc6f192af42e80fbfd8467e0c068b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 562656c8ed06737fedb4dd348d788e484786873855c0ecd5fb951c651ed2383a90a738c2cd64f444155589b07df9c08881964e0fafbaeebdffd11d4200d47bce
|
7
|
+
data.tar.gz: 3c77e9a13c67a68b76797583a83179259ffca73e5a754902b31e99c51c8c2874711d07a3943836669dea4e7025d2147090e0f69672dc3f46d8589850f339ad4b
|
data/README.md
CHANGED
@@ -13,13 +13,13 @@ This is a port of the java functional library [Totally Lazy](https://code.google
|
|
13
13
|
In your bundler Gemfile
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
gem totally_lazy, '~>0.0.
|
16
|
+
gem totally_lazy, '~>0.0.2'
|
17
17
|
```
|
18
18
|
|
19
19
|
Or with rubygems
|
20
20
|
|
21
21
|
```
|
22
|
-
gem install
|
22
|
+
gem install totally_lazy
|
23
23
|
```
|
24
24
|
|
25
25
|
### Examples
|
@@ -33,6 +33,8 @@ sequence(1,2,3).take(2) # lazily returns 1,2
|
|
33
33
|
sequence(1,2,3).drop(2) # lazily returns 3
|
34
34
|
sequence(1,2,3).tail # lazily returns 2,3
|
35
35
|
sequence(1,2,3).head # eagerly returns 1
|
36
|
+
sequence(1,2,3).head_option # eagerly returns an option
|
37
|
+
some(sequence(1,2,3)).get_or_else(empty) # eagerly returns value or else empty sequence
|
36
38
|
```
|
37
39
|
|
38
40
|
Naturally you can combine these operations together:
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
data/lib/option.rb
CHANGED
@@ -46,11 +46,11 @@ module Option
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def get_or_nil
|
49
|
-
@content
|
49
|
+
blank? ? nil : @content
|
50
50
|
end
|
51
51
|
|
52
52
|
def get_or_throw(exception)
|
53
|
-
blank? ?
|
53
|
+
blank? ? raise(exception) : @content
|
54
54
|
end
|
55
55
|
|
56
56
|
def to_seq
|
@@ -79,7 +79,7 @@ module Option
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def blank?
|
82
|
-
@content.
|
82
|
+
@content.respond_to?(:empty?) ? empty? : !self
|
83
83
|
end
|
84
84
|
|
85
85
|
end
|
data/spec/option_spec.rb
CHANGED
@@ -18,11 +18,11 @@ describe 'Option' do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should support join' do
|
21
|
-
expect(option(1).join(sequence(2,3))).to eq(sequence(1,2,3))
|
21
|
+
expect(option(1).join(sequence(2, 3))).to eq(sequence(1, 2, 3))
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should get value of some' do
|
25
|
-
|
25
|
+
expect(option(1).get).to eq(1)
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'should not get value of none' do
|
@@ -30,15 +30,18 @@ describe 'Option' do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should get or else' do
|
33
|
-
|
33
|
+
expect(option(1).get_or_else(2)).to eq(1)
|
34
|
+
expect(option(empty).get_or_else(2)).to eq(2)
|
34
35
|
end
|
35
36
|
|
36
37
|
it 'should get or nil' do
|
37
|
-
|
38
|
+
expect(option(1).get_or_nil).to eq(1)
|
39
|
+
expect(option(empty).get_or_nil).to eq(nil)
|
38
40
|
end
|
39
41
|
|
40
42
|
it 'should get or raise exception' do
|
41
|
-
|
43
|
+
expect(option(1).get_or_throw(Exception)).to eq(1)
|
44
|
+
expect { option(empty).get_or_throw(Exception) }.to raise_error(Exception)
|
42
45
|
end
|
43
46
|
|
44
47
|
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: totally_lazy 0.0.2 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "totally_lazy"
|
9
|
+
s.version = "0.0.2"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Kingsley Hendrickse"]
|
14
|
+
s.date = "2014-08-15"
|
15
|
+
s.description = "Port of java functional library totally lazy to ruby"
|
16
|
+
s.email = "kingsleyhendrickse@me.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.md"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".rspec",
|
24
|
+
"Gemfile",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/option.rb",
|
30
|
+
"lib/pair.rb",
|
31
|
+
"lib/sequence.rb",
|
32
|
+
"lib/totally_lazy.rb",
|
33
|
+
"lib/tuple.rb",
|
34
|
+
"spec/option_spec.rb",
|
35
|
+
"spec/pair_spec.rb",
|
36
|
+
"spec/sequence_spec.rb",
|
37
|
+
"spec/tuple_spec.rb",
|
38
|
+
"totally_lazy.gemspec"
|
39
|
+
]
|
40
|
+
s.homepage = "http://github.com/kingsleyh/totally_lazy"
|
41
|
+
s.licenses = ["MIT"]
|
42
|
+
s.rubygems_version = "2.2.2"
|
43
|
+
s.summary = "Port of java functional library totally lazy to ruby"
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
s.specification_version = 4
|
47
|
+
|
48
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
49
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.0.0"])
|
50
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
51
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
52
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
53
|
+
s.add_development_dependency(%q<rspec_html_formatter>, ["~> 0.3.0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, ["~> 3.0.0"])
|
56
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
59
|
+
s.add_dependency(%q<rspec_html_formatter>, ["~> 0.3.0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<rspec>, ["~> 3.0.0"])
|
63
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
66
|
+
s.add_dependency(%q<rspec_html_formatter>, ["~> 0.3.0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kingsley Hendrickse
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- spec/pair_spec.rb
|
105
105
|
- spec/sequence_spec.rb
|
106
106
|
- spec/tuple_spec.rb
|
107
|
+
- totally_lazy.gemspec
|
107
108
|
homepage: http://github.com/kingsleyh/totally_lazy
|
108
109
|
licenses:
|
109
110
|
- MIT
|