monad-oxide 0.9.0 → 0.11.0

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.
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 +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d74a96544bd662cb0fcf3131ca119560a4c0811e27a0668b24ef4bca351c610f
4
- data.tar.gz: d93aa6573dd0bc7ac9529f828b630a421e9d527d1a75b6074fe8879a7defd52e
3
+ metadata.gz: 33bf53ee100fbb7245db4b0c04712db889c4ec8936a86502b94ddbed696ae76a
4
+ data.tar.gz: a16a6e4f90f07361d99fefb05c9693e4d1176111e9cb04bb50a8fa729f3897dd
5
5
  SHA512:
6
- metadata.gz: 793f5483be340bb1e5789fb29488a8c040b803848b5579fbc29e50af13006b1699fa75402bf796ead161031835c246908e7d543c98994c82d43d5a56641d8d43
7
- data.tar.gz: 998649fd304a9cfe9ce05dea05b67ac88e616a3e4a8a22c707c0ff4661ac5574170a016a5d21bf1c0f610ec5de2543e0817ed71830ea59a8682b6a43e1c51ab1
6
+ metadata.gz: cad21e595bacf6a29985216ea7976d9e3698bcfb4365defc2d88b5bb99d15b4d4146630572f03309512d843fc1aff8fd3bd26171e8d061b6b362d93831de467a
7
+ data.tar.gz: c61f8e86f2058a1ba267c05c9691226c7df24aed3586a0c7431f543dce593a1b47182be3775534ad49a928b49e36d16cba2712d17335b5a9eca9f63f25f2c48d
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.11.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: org-ruby