result-monad 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06e97a1d838923904e635d8db6d4a2d1aaa408fb
4
- data.tar.gz: 664c8d07c7c60c78c4a420cd5d1a96a94794bda0
3
+ metadata.gz: f6827e932e166f2ef6c04af4fab7a181e7ae2f60
4
+ data.tar.gz: 5b9302941c4cd0244b35991fcecd7cd825511f10
5
5
  SHA512:
6
- metadata.gz: 9fb60c7bd5f36285a4d4ab4f10970698cb82b40bf4e60b09f94d13095a6be1f944ee8a70ad4bdc695cbbe20b01e643976028fa4a7d029e472f22394fa542cf07
7
- data.tar.gz: 6cf9622293538460ce6760b9d5a1538263e51adcf135c95601a5822f94f19e4ec39a8330eecd68a9831f69a3dab2d944a2f552dc3b5f8c0244a9175c10e66a1a
6
+ metadata.gz: db75419f936a2215d174ffd2a733fc1d9b04a927c81738d429f0deecc3398f9df2cf165301b06592267da8bff0a37ea1ebf94e0481c375c2236935fba47cd3da
7
+ data.tar.gz: 3991d42013a5f7690a49c9a5cc7f8cf2167c243fa40ce839ad251fbb64cb646428a5bb1c0c230ad171438316477d540598bc316dc1ea18fb11ca8790b5d86646
@@ -1,19 +1,19 @@
1
1
  class Error
2
- def initialize(error)
3
- @error = error
2
+ def initialize(value)
3
+ @value = value
4
4
  end
5
5
 
6
6
  def map!(&block)
7
- @error = Capture {block.call(@error)}
7
+ @value = Capture {block.call(@value)}
8
8
  self
9
9
  end
10
10
 
11
11
  def map(&block)
12
- capture_as_error { block.call(@error) }
12
+ capture_as_error { block.call(@value) }
13
13
  end
14
14
 
15
15
  def to_s
16
- "Error(#{@error})"
16
+ "Error(#{@value})"
17
17
  end
18
18
 
19
19
  private
@@ -1,3 +1,3 @@
1
1
  class Result
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/result-monad.rb CHANGED
@@ -105,6 +105,24 @@ class Result
105
105
  ok? ? unwrap : cons
106
106
  end
107
107
 
108
+ def map_when(kind, &block)
109
+ @m.map(&block) if val.is_a?(kind)
110
+ self
111
+ end
112
+
113
+ def do_when(kind, &block)
114
+ Capture { block.call } if val.is_a?(kind)
115
+ self
116
+ end
117
+
118
+ def raise_or_return!
119
+ if ok?
120
+ return val
121
+ else
122
+ raise val
123
+ end
124
+ end
125
+
108
126
  # Constructors
109
127
  def self.error(error)
110
128
  new(Error.new(error))
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: result-monad
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zachary Daniel