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.
- checksums.yaml +4 -4
- data/lib/err.rb +10 -0
- data/lib/ok.rb +11 -0
- data/lib/result.rb +11 -0
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9591d9d197cf1ef8f426a5839f07c13cfd8e119b30108e39308df8a3e9a917c8
|
4
|
+
data.tar.gz: 9b8c90000b771ad86ada0703ab80ccc680ea3b93c56e6f610d802b30db772c2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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