monad-oxide 0.5.0 → 0.7.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 +10 -0
  3. data/lib/ok.rb +11 -0
  4. data/lib/result.rb +11 -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: eb1f3b4527006d3ab2dac1f0bd4f4a34ba51b5322be9f399b8aac2c329a0522f
4
- data.tar.gz: cea1e0e146c40f451d1cfacf37b8c00b588bbd54b45426a1ba2d6b66e7a51017
3
+ metadata.gz: 9591d9d197cf1ef8f426a5839f07c13cfd8e119b30108e39308df8a3e9a917c8
4
+ data.tar.gz: 9b8c90000b771ad86ada0703ab80ccc680ea3b93c56e6f610d802b30db772c2c
5
5
  SHA512:
6
- metadata.gz: d6e010dd7e59da9bc9041079e58e75b4c6de45dfb4628489023720d637c963d773a1e98890e5ed83c133ae38608cd3f2454cb64f44551a93e93a4ed91a031215
7
- data.tar.gz: 7f51e98348f6f5588b2d57bbf6ad998c63d84a36aab3b9fd4de953766c70b968c779aa7ceeb5d3f338cab7c30924a20f39f861810756ad58d3a18f51b2e7b767
6
+ metadata.gz: b1751012d53a844e5f8b05049915c1f4c30b791548fc99d11be1414773d96f62c3e9a918235a8f0675bd497cec20fa0cbb2bac4522fa98bc616a76f2e13ccac7
7
+ data.tar.gz: 80a29ddd6ed21616a09d833ced0562491356be54c40383a5b0a8281d2c68bcc69fcd8972d0b4e65895a48970856b968efb2d3334e36d2557fbbdf730cf127654
data/lib/err.rb CHANGED
@@ -166,5 +166,15 @@ module MonadOxide
166
166
  @data
167
167
  end
168
168
 
169
+ ##
170
+ # Safely unwrap the `Result`. In the case of `Err`, this returns the
171
+ # provided default value.
172
+ #
173
+ # @param [T] x The value that will be returned.
174
+ # @return [T] The `x` value.
175
+ def unwrap_or(x)
176
+ x
177
+ end
178
+
169
179
  end
170
180
  end
data/lib/ok.rb CHANGED
@@ -123,5 +123,16 @@ module MonadOxide
123
123
  "#{self.class} with #{@data.inspect} could not be unwrapped as an Err.",
124
124
  )
125
125
  end
126
+
127
+ ##
128
+ # Safely unwrap the `Result`. In the case of `Ok`, this returns the
129
+ # data in the Ok.
130
+ #
131
+ # @param [B] x The value that will be returned.
132
+ # @return [A] The data in the Ok.
133
+ def unwrap_or(_)
134
+ @data
135
+ end
136
+
126
137
  end
127
138
  end
data/lib/result.rb CHANGED
@@ -225,5 +225,16 @@ module MonadOxide
225
225
  def unwrap_err()
226
226
  Err.new(ResultMethodNotImplementedError.new())
227
227
  end
228
+
229
+ ##
230
+ # Attempt to safely access the `Result` data. This always returns a value
231
+ # instead of raising an Exception. In the case of `Ok`, the data is
232
+ # returned. In the case of `Err`, the value provided is returned.
233
+ # @param _ [B] The value to use for `Err`.
234
+ # @return [T|B] The inner data of this `Ok` or the passee value.
235
+ def unwrap_or(_)
236
+ Err.new(ResultMethodNotImplementedError.new())
237
+ end
238
+
228
239
  end
229
240
  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.5.0'
6
+ VERSION='0.7.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.5.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett