monadic 0.7.3 → 0.7.4
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.
- data/CHANGELOG.md +2 -0
- data/lib/monadic/maybe.rb +4 -0
- data/lib/monadic/version.rb +1 -1
- data/spec/maybe_spec.rb +6 -52
- data/spec/nothing_spec.rb +57 -0
- metadata +4 -2
data/CHANGELOG.md
CHANGED
data/lib/monadic/maybe.rb
CHANGED
data/lib/monadic/version.rb
CHANGED
data/spec/maybe_spec.rb
CHANGED
@@ -21,58 +21,7 @@ describe Monadic::Maybe do
|
|
21
21
|
|
22
22
|
it 'on non-existant methods, returns Nothing' do
|
23
23
|
Maybe({}).a.b.c.should == Nothing
|
24
|
-
end
|
25
|
-
|
26
|
-
describe Monadic::Nothing do
|
27
|
-
it_behaves_like 'a Monad' do
|
28
|
-
let(:monad) { Nothing }
|
29
|
-
end
|
30
|
-
|
31
|
-
it '===' do
|
32
|
-
(Maybe(nil) === Nothing).should be_true
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'Nothing stays Nothing' do
|
36
|
-
Maybe(nil).fetch.should == Nothing
|
37
|
-
Maybe(nil)._.should == Nothing
|
38
|
-
Maybe(nil).empty?.should be_true
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'Nothing#to_s is "Nothing"' do
|
42
|
-
option = Maybe(nil)
|
43
|
-
"#{option}".should == "Nothing"
|
44
|
-
Nothing.to_s.should == "Nothing"
|
45
|
-
Nothing.to_s(1, 2).should == "Nothing"
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'Nothing is always empty' do
|
49
|
-
Nothing.empty?.should be_true
|
50
|
-
Maybe(nil).empty?.should be_true
|
51
|
-
end
|
52
|
-
|
53
|
-
it '[] as value always returns Nothing()' do
|
54
|
-
Maybe([]).a.should == Nothing
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'is always empty and false' do
|
58
|
-
Nothing.empty?.should be_true
|
59
|
-
Nothing.truly?.should be_false
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'returns Nothing when calling #name' do
|
63
|
-
hd = Nothing
|
64
|
-
hd.name.should == Monadic::Nothing
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'Nothing#or returns the alternative' do
|
68
|
-
Maybe(nil).or(1).should == Just(1)
|
69
|
-
Nothing.or(1).should == Just(1)
|
70
|
-
Nothing.or(Just(nil)).should == Just(nil)
|
71
|
-
Nothing.something.or(1).should == Just(1)
|
72
|
-
Nothing.something.or(Just(nil)).should == Just(nil)
|
73
|
-
Nothing.or('').should == Just('')
|
74
|
-
end
|
75
|
-
end
|
24
|
+
end
|
76
25
|
|
77
26
|
describe Monadic::Just do
|
78
27
|
it_behaves_like 'a Monad' do
|
@@ -189,4 +138,9 @@ describe Monadic::Maybe do
|
|
189
138
|
Maybe(nil).proxy.downcase.capitalize.bar.should == Nothing
|
190
139
|
Maybe({a: 1}).proxy.__fetch__.should == {a: 1}
|
191
140
|
end
|
141
|
+
|
142
|
+
it "maybe_map takes an Enumerable and Maybe's each element " do
|
143
|
+
Maybe([{}]).flat_map { |e| e[:angry]}.compact.should == Nothing
|
144
|
+
Maybe([{:angry => 'nerds'}, {}]).flat_map { |e| e[:angry]}.compact.should == Just(['nerds'])
|
145
|
+
end
|
192
146
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Monadic::Nothing do
|
4
|
+
it_behaves_like 'a Monad' do
|
5
|
+
let(:monad) { Nothing }
|
6
|
+
end
|
7
|
+
|
8
|
+
it '===' do
|
9
|
+
(Maybe(nil) === Nothing).should be_true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'Nothing stays Nothing' do
|
13
|
+
Maybe(nil).fetch.should == Nothing
|
14
|
+
Maybe(nil)._.should == Nothing
|
15
|
+
Maybe(nil).empty?.should be_true
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'Nothing#to_s is "Nothing"' do
|
19
|
+
option = Maybe(nil)
|
20
|
+
"#{option}".should == "Nothing"
|
21
|
+
Nothing.to_s.should == "Nothing"
|
22
|
+
Nothing.to_s(1, 2).should == "Nothing"
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'Nothing#to_json is nil' do
|
26
|
+
Maybe(nil).to_json(:only => :a).should == 'null'
|
27
|
+
Nothing.to_json.should == 'null'
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'Nothing is always empty' do
|
31
|
+
Nothing.empty?.should be_true
|
32
|
+
Maybe(nil).empty?.should be_true
|
33
|
+
end
|
34
|
+
|
35
|
+
it '[] as value always returns Nothing()' do
|
36
|
+
Maybe([]).a.should == Nothing
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'is always empty and false' do
|
40
|
+
Nothing.empty?.should be_true
|
41
|
+
Nothing.truly?.should be_false
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'returns Nothing when calling #name' do
|
45
|
+
hd = Nothing
|
46
|
+
hd.name.should == Monadic::Nothing
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'Nothing#or returns the alternative' do
|
50
|
+
Maybe(nil).or(1).should == Just(1)
|
51
|
+
Nothing.or(1).should == Just(1)
|
52
|
+
Nothing.or(Just(nil)).should == Just(nil)
|
53
|
+
Nothing.something.or(1).should == Just(1)
|
54
|
+
Nothing.something.or(Just(nil)).should == Just(nil)
|
55
|
+
Nothing.or('').should == Just('')
|
56
|
+
end
|
57
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: monadic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- spec/maybe_spec.rb
|
161
161
|
- spec/monad_axioms.rb
|
162
162
|
- spec/monad_spec.rb
|
163
|
+
- spec/nothing_spec.rb
|
163
164
|
- spec/spec_helper.rb
|
164
165
|
- spec/try_spec.rb
|
165
166
|
- spec/validation_spec.rb
|
@@ -197,6 +198,7 @@ test_files:
|
|
197
198
|
- spec/maybe_spec.rb
|
198
199
|
- spec/monad_axioms.rb
|
199
200
|
- spec/monad_spec.rb
|
201
|
+
- spec/nothing_spec.rb
|
200
202
|
- spec/spec_helper.rb
|
201
203
|
- spec/try_spec.rb
|
202
204
|
- spec/validation_spec.rb
|