monad-oxide 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/lib/err.rb +23 -0
  3. data/lib/ok.rb +26 -2
  4. data/lib/result.rb +45 -0
  5. data/lib/version.rb +1 -1
  6. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d74a96544bd662cb0fcf3131ca119560a4c0811e27a0668b24ef4bca351c610f
4
- data.tar.gz: d93aa6573dd0bc7ac9529f828b630a421e9d527d1a75b6074fe8879a7defd52e
3
+ metadata.gz: 12758d7a4698325f9f371dd587d52879bcb2088c89f6691600e56d4525d428a5
4
+ data.tar.gz: a7fad1a246adc14c63fcc1ac4d9c1f4e01b658b0077b0eb058218822eadcc9a8
5
5
  SHA512:
6
- metadata.gz: 793f5483be340bb1e5789fb29488a8c040b803848b5579fbc29e50af13006b1699fa75402bf796ead161031835c246908e7d543c98994c82d43d5a56641d8d43
7
- data.tar.gz: 998649fd304a9cfe9ce05dea05b67ac88e616a3e4a8a22c707c0ff4661ac5574170a016a5d21bf1c0f610ec5de2543e0817ed71830ea59a8682b6a43e1c51ab1
6
+ metadata.gz: ebdc0c265cd9a2dfaef992c75fbb62675608fe74247e9fc00cb67201c6b6280999104d72926755990b38ab6b8ad1b5d20c3be9899446c787cf7765222129fce3
7
+ data.tar.gz: e27ae5ed41c7fed7f7fb90afc6a43b1165aeb41daf1295f756428cbf77a782f9210e33766b15ad973fae9760752cdcaa4d6ac96f53e9b34abbe63798da0ac2d4
data/lib/err.rb CHANGED
@@ -188,6 +188,16 @@ module MonadOxide
188
188
  @data
189
189
  end
190
190
 
191
+ ##
192
+ # Safely unwrap the `Result`. In the case of `Err`, this returns the
193
+ # wrapped value.
194
+ #
195
+ # @param _f A dummy function. Not used.
196
+ # @return [T] The wrapped value.
197
+ def unwrap_err_or_else(f=nil, &_block)
198
+ @data
199
+ end
200
+
191
201
  ##
192
202
  # Safely unwrap the `Result`. In the case of `Err`, this returns the
193
203
  # provided default value.
@@ -198,5 +208,18 @@ module MonadOxide
198
208
  x
199
209
  end
200
210
 
211
+ ##
212
+ # Safely unwrap the `Result`. In the case of `Err`, this uses the provided
213
+ # function to produce a value.
214
+ #
215
+ # @param f [Proc<B>] The function to call. Could be a block
216
+ # instead. Takes nothing and returns a [B=Object].
217
+ # @yield Will yield a block that takes nothing and returns a [B=Object].
218
+ # Same as `f' parameter.
219
+ # @return [B] The value returned from `f`.
220
+ def unwrap_or_else(f=nil, &block)
221
+ (f || block).call()
222
+ end
223
+
201
224
  end
202
225
  end
data/lib/ok.rb CHANGED
@@ -146,13 +146,37 @@ module MonadOxide
146
146
  )
147
147
  end
148
148
 
149
+ ##
150
+ # Safely unwrap the `Result`. In the case of `Ok`, this uses the provided
151
+ # function to produce a value.
152
+ #
153
+ # @param f [Proc<B>] The function to call. Could be a block
154
+ # instead. Takes nothing and returns a [B=Object].
155
+ # @yield Will yield a block that takes nothing and returns a [B=Object].
156
+ # Same as `f' parameter.
157
+ # @return [B] The value returned from `f`.
158
+ def unwrap_err_or_else(f=nil, &block)
159
+ (f || block).call()
160
+ end
161
+
149
162
  ##
150
163
  # Safely unwrap the `Result`. In the case of `Ok`, this returns the
151
164
  # data in the Ok.
152
165
  #
153
- # @param [B] x The value that will be returned.
166
+ # @param [B] _x The value that will be returned.
154
167
  # @return [A] The data in the Ok.
155
- def unwrap_or(_)
168
+ def unwrap_or(_x)
169
+ @data
170
+ end
171
+
172
+ ##
173
+ # Safely unwrap the `Result`. In the case of `Ok`, this returns the
174
+ # wrapped value.
175
+ #
176
+ # @param f [Proc<B>] A dummy function. Not used.
177
+ # instead. Takes nothing and returns a [B=Object].
178
+ # @return [B] The value returned from `f`.
179
+ def unwrap_or_else(_f=nil, &_block)
156
180
  @data
157
181
  end
158
182
 
data/lib/result.rb CHANGED
@@ -240,6 +240,21 @@ module MonadOxide
240
240
  Err.new(ResultMethodNotImplementedError.new())
241
241
  end
242
242
 
243
+ ##
244
+ # Safely unwrap the `Result` but with lazy evaluation. In the case of
245
+ # `Err`, this returns the wrapped value. For `Ok` the function provided is
246
+ # evaluated and its returned value is what is returned.
247
+ #
248
+ # @param f [Proc<B>] The function to call for `Ok`. Could be a block
249
+ # instead. Takes nothing and returns a [B=Object].
250
+ # @yield Will yield a block for `Ok` that takes nothing and returns a
251
+ # [B=Object]. Same as `f' parameter.
252
+ # @return [T|B] The wrapped value for `Err` and the returned from `f` for
253
+ # `Ok`.
254
+ def unwrap_err_or_else(_f)
255
+ raise ResultMethodNotImplementedError.new()
256
+ end
257
+
243
258
  ##
244
259
  # Attempt to safely access the `Result` data. This always returns a value
245
260
  # instead of raising an Exception. In the case of `Ok`, the data is
@@ -250,5 +265,35 @@ module MonadOxide
250
265
  Err.new(ResultMethodNotImplementedError.new())
251
266
  end
252
267
 
268
+ ##
269
+ # Safely unwrap the `Result` but with lazy evaluation. In the case of
270
+ # `Ok`, this returns the wrapped value. For `Err` the function provided is
271
+ # evaluated and its returned value is what is returned.
272
+ #
273
+ # @param f [Proc<B>] The function to call for `Err`. Could be a block
274
+ # instead. Takes nothing and returns a [B=Object].
275
+ # @yield Will yield a block for `Err` that takes nothing and returns a
276
+ # [B=Object]. Same as `f' parameter.
277
+ # @return [T|B] The wrapped value for `Ok` and the returned from `f` for
278
+ # `Err`.
279
+ def unwrap_or_else(_f)
280
+ raise ResultMethodNotImplementedError.new()
281
+ end
282
+
283
+ ##
284
+ # Safely unwrap the `Result` but with lazy evaluation. In the case of `Ok`,
285
+ # this returns the wrapped value. For `Err` the function provided is
286
+ # evaluated and its returned value is what is returned.
287
+ #
288
+ # @param f [Proc<B>] The function to call for `Err`. Could be a block
289
+ # instead. Takes nothing and returns a [B=Object].
290
+ # @yield Will yield a block for `Err` that takes nothing and returns a
291
+ # [B=Object]. Same as `f' parameter.
292
+ # @return [T|B] The wrapped value for `Ok` and the returned from `f` for
293
+ # `Err`.
294
+ def unwrap_or_else(_f)
295
+ raise ResultMethodNotImplementedError.new()
296
+ end
297
+
253
298
  end
254
299
  end
data/lib/version.rb CHANGED
@@ -3,5 +3,5 @@ module MonadOxide
3
3
  # This version is locked to 0.x.0 because semver is a lie and this project
4
4
  # uses CICD to push new versions. Any commits that appear on main will result
5
5
  # in a new version of the gem created and published.
6
- VERSION='0.9.0'
6
+ VERSION='0.10.0'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monad-oxide
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett