monadic 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.4.0
4
+ `#or` returns for Nothing an alternative
5
+
6
+ Maybe(nil).or(1) == 1
7
+ Maybe(1).or(2) == 1
8
+
3
9
  ## v0.3.0
4
10
  **BREAKING CHANGES**
5
11
  `#to_s` returns the inner value converted to string
data/README.md CHANGED
@@ -83,12 +83,15 @@ Treat it like an array:
83
83
  Maybe(nil).to_a == []
84
84
  ```
85
85
 
86
- `to_s`
86
+ `#to_s`
87
87
  ```ruby
88
88
  Maybe(nil).to_s == 'Nothing'
89
89
  Maybe(1).to_s == '1'
90
90
  ```
91
91
 
92
+ `#or`
93
+ Maybe(nil).or(1) == 1
94
+ Maybe(1).or(2) == 1
92
95
 
93
96
  Falsey values (kind-of) examples:
94
97
 
data/lib/monadic/maybe.rb CHANGED
@@ -42,6 +42,10 @@ module Monadic
42
42
  Maybe(@value.__send__(m, *args))
43
43
  end
44
44
 
45
+ def or(other)
46
+ self
47
+ end
48
+
45
49
  def to_s
46
50
  @value.to_s
47
51
  end
@@ -62,6 +66,10 @@ module Monadic
62
66
  self
63
67
  end
64
68
 
69
+ def or(other)
70
+ Maybe(other)
71
+ end
72
+
65
73
  def to_ary
66
74
  []
67
75
  end
@@ -1,3 +1,3 @@
1
1
  module Monadic
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/spec/maybe_spec.rb CHANGED
@@ -52,6 +52,10 @@ describe Monadic::Maybe do
52
52
  hd = Nothing
53
53
  hd.name.should == Monadic::Nothing
54
54
  end
55
+
56
+ it 'Nothing#or returns the alternative' do
57
+ Maybe(nil).or(1).should == Just(1)
58
+ end
55
59
  end
56
60
 
57
61
  describe Monadic::Just do
@@ -67,6 +71,11 @@ describe Monadic::Maybe do
67
71
  it 'Just#to_s is "value"' do
68
72
  Just.unit(123).to_s.should == "123"
69
73
  end
74
+
75
+ it 'Just#or return self' do
76
+ Maybe(1).or(2).should == Just(1)
77
+ end
78
+
70
79
  end
71
80
 
72
81
  it 'calling methods on Maybe always returns an Maybe with the transformed value' do
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.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -173,7 +173,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
173
  version: '0'
174
174
  segments:
175
175
  - 0
176
- hash: -2586124281524305504
176
+ hash: -4582123822322674017
177
177
  required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  none: false
179
179
  requirements:
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  segments:
184
184
  - 0
185
- hash: -2586124281524305504
185
+ hash: -4582123822322674017
186
186
  requirements: []
187
187
  rubyforge_project:
188
188
  rubygems_version: 1.8.24