monad-oxide 0.6.0 → 0.7.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 +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: 9152af4e006e8a978a78be5124827b09d97ec352f5415cbf32d28db8eef6918a
4
- data.tar.gz: e197a94f8b60ba971f112eb9ea49f82773acfc378ab5595dc1536575cdc27dd7
3
+ metadata.gz: 9591d9d197cf1ef8f426a5839f07c13cfd8e119b30108e39308df8a3e9a917c8
4
+ data.tar.gz: 9b8c90000b771ad86ada0703ab80ccc680ea3b93c56e6f610d802b30db772c2c
5
5
  SHA512:
6
- metadata.gz: 7cb457a2987b557e1a32cc9b7dd0587a825c2bcdcd6c4f99e04774a3b858cf0f19a8775163287a6db0500833fe804a2bdd5b6dc26293267b75eabf763597ecad
7
- data.tar.gz: 612b7b37f4e4a2cead728bd7465909d88375c72c1b169cd2e1880b4a173fd585831ed88acaad2fd88becaeda03aebcffa6171f924cfba6b00e94da1307a78e92
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.6.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.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett