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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/option.rb +24 -0
  3. data/lib/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ef9afae9321a36b11f966859ba1e031288d0c532f758e4f9b7063234ab8fe2a
4
- data.tar.gz: 9c1e4528650956209644f9095db174b510a4277e79c96d11f137ef1bb1ed708c
3
+ metadata.gz: 527a364e877c458b44d2f94cc3d59adace690bbee75e6da602daef77319369e2
4
+ data.tar.gz: dc568c5996d9dc36ae83cebf34cec5289fe6ea8e319c4ad1dde0aae1231e1e58
5
5
  SHA512:
6
- metadata.gz: 5270dd501e132f3396184508e05a1dc41e8ff119689a5a44a4b6c27bfcc4b23d5db18d53f8b5cdd68dc1915debe134ac27c8516fe143d165ba023414dbbc3d6f
7
- data.tar.gz: 7badd118397b1bddc5a5c65b2e23f2c87e57d3c1ac10f774ee6863f3116aed9923f21d43693dbb1e4402128cd5c32e1640a7a8071c2083d29cfcdf977116ac9f
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.15.0'
6
+ VERSION='0.16.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.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett