monad-oxide 0.15.0 → 0.16.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.
- checksums.yaml +4 -4
- data/lib/option.rb +24 -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: 527a364e877c458b44d2f94cc3d59adace690bbee75e6da602daef77319369e2
|
|
4
|
+
data.tar.gz: dc568c5996d9dc36ae83cebf34cec5289fe6ea8e319c4ad1dde0aae1231e1e58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8bc31b055fcff603efff03d5057836be330c031210f77397c169a220777f3acb4ac583aab47b09d320c5bf52b209dac44b16c626d3f66d334a5c24f8e9dc2fa8
|
|
7
|
+
data.tar.gz: 6d1c32430d663eb3471ff25f0eb42c79249599e131ce866d422bad051c6bb4e6d74221ef59a55714a90216ed640c7d259e649635a22cda4ebf5e7513c89404fe
|
data/lib/option.rb
CHANGED
|
@@ -191,6 +191,30 @@ module MonadOxide
|
|
|
191
191
|
raise OptionMethodNotImplementedError.new()
|
|
192
192
|
end
|
|
193
193
|
|
|
194
|
+
##
|
|
195
|
+
# Use pattern matching to work with both Some and None variants. This is
|
|
196
|
+
# useful when it is desirable to have both variants handled in the same
|
|
197
|
+
# location. It can also be useful when either variant can coerced into a
|
|
198
|
+
# non-Option type.
|
|
199
|
+
#
|
|
200
|
+
# Ruby has no built-in pattern matching, but the next best thing is a
|
|
201
|
+
# Hash using the Option classes themselves as the keys.
|
|
202
|
+
#
|
|
203
|
+
# Tests for this are found in Some and None's tests.
|
|
204
|
+
#
|
|
205
|
+
# @param matcher [Hash<Class, Proc<T, R>] matcher The matcher to match
|
|
206
|
+
# upon.
|
|
207
|
+
# @option matcher [Proc] MonadOxide::Some The branch to execute for Some.
|
|
208
|
+
# @option matcher [Proc] MonadOxide::None The branch to execute for None.
|
|
209
|
+
# @return [R] The return value of the executed Proc.
|
|
210
|
+
def match(matcher)
|
|
211
|
+
if self.kind_of?(None)
|
|
212
|
+
matcher[self.class].call()
|
|
213
|
+
else
|
|
214
|
+
matcher[self.class].call(@data)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
194
218
|
end
|
|
195
219
|
|
|
196
220
|
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
|
+
VERSION='0.16.0'
|
|
7
7
|
end
|