monad-oxide 0.15.0 → 0.17.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ef9afae9321a36b11f966859ba1e031288d0c532f758e4f9b7063234ab8fe2a
4
- data.tar.gz: 9c1e4528650956209644f9095db174b510a4277e79c96d11f137ef1bb1ed708c
3
+ metadata.gz: 7f4add1af70591ea0b72483b5608bb2c0e08d06d29d2c34dc2d952d501c9f632
4
+ data.tar.gz: c7a0d1d2a47c157faf8aa069425e37b11964b9dc81ff6d3329b51dd352350d51
5
5
  SHA512:
6
- metadata.gz: 5270dd501e132f3396184508e05a1dc41e8ff119689a5a44a4b6c27bfcc4b23d5db18d53f8b5cdd68dc1915debe134ac27c8516fe143d165ba023414dbbc3d6f
7
- data.tar.gz: 7badd118397b1bddc5a5c65b2e23f2c87e57d3c1ac10f774ee6863f3116aed9923f21d43693dbb1e4402128cd5c32e1640a7a8071c2083d29cfcdf977116ac9f
6
+ metadata.gz: 37c193a394b45179137bd13127c0907b9848fb87a116e81e9de5b821aca3e967e5559209861c6da200ea59bc30d35f1b1a8591cca0224a8cc617ccc5e39b3e01
7
+ data.tar.gz: fefeeef05166cee8ae902fec3af6e47d848dcacc3da0008bade58d896ca1d9e9846f8f549348b9834d4ba44cd63efa2eb912c4a8b8cbbb2315d9ac3fff035d74
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ ################################################################################
3
+ # Defines a helper for concurrent/promises.
4
+ ################################################################################
5
+
6
+ require 'concurrent/promises'
7
+ require_relative '../monad-oxide'
8
+
9
+ class Concurrent::Promises::Future
10
+
11
+ ##
12
+ # Coerces a Current::Promises::Future into a MonadOxide::Result. This
13
+ # behavior forces the Future to finalize, and thus is blocking behavior.
14
+ # A successful Future becomes a MonadOxide::Ok, and a failed Future becomes a
15
+ # MonadOxide::Err.
16
+ # @return [MonadOxide::Result<A, E>] A coerced Result from the Future,
17
+ # containing whatever value the Future was holding.
18
+ def into_result()
19
+ success, value, err = self.result()
20
+ success ? MonadOxide.ok(value) : MonadOxide.err(
21
+ # err isn't actually the error unless someone called rescue on the promise
22
+ # chain. It's pretty weird. So we have to check for both.
23
+ err.nil?() ? value : err,
24
+ )
25
+ end
26
+
27
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module MonadOxide
3
4
  ##
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  ################################################################################
3
- #
3
+ # Defines Left, a variant of Either.
4
4
  ################################################################################
5
5
 
6
6
  require_relative './error'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './result'
2
4
  require_relative './error'
3
5
 
@@ -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
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
  ################################################################################
3
- #
3
+ # Defines Right, a variant of Either.
4
4
  ################################################################################
5
5
 
6
6
  require_relative './error'
@@ -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.17.0'
7
7
  end
data/lib/monad-oxide.rb CHANGED
@@ -1,14 +1,14 @@
1
- require_relative './result'
2
- require_relative './err'
3
- require_relative './ok'
4
- require_relative './either'
5
- require_relative './left'
6
- require_relative './right'
7
- require_relative './option'
8
- require_relative './some'
9
- require_relative './none'
10
- require_relative './array'
11
- require_relative './version'
1
+ # frozen_string_literal: true
2
+ require_relative './monad-oxide/result'
3
+ require_relative './monad-oxide/err'
4
+ require_relative './monad-oxide/ok'
5
+ require_relative './monad-oxide/either'
6
+ require_relative './monad-oxide/left'
7
+ require_relative './monad-oxide/right'
8
+ require_relative './monad-oxide/array'
9
+ require_relative './monad-oxide/version'
10
+ # Intentionally do not require helpers which inflict external dependencies, such
11
+ # as ./concurrent-promises.rb which requires the 'concurrent' gem.
12
12
 
13
13
  ##
14
14
  # The top level module for the monad-oxide library. Of interest, @see `Result',
metadata CHANGED
@@ -1,14 +1,14 @@
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.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Logan Barnett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-07 00:00:00.000000000 Z
11
+ date: 2026-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: org-ruby
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: concurrent-ruby
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: |
70
84
  Monad-Oxide is a port of Rust's built-in monads from std, such as Result and
71
85
  Option. This enables better reasoning about error handling and possibly missing
@@ -75,19 +89,20 @@ executables: []
75
89
  extensions: []
76
90
  extra_rdoc_files: []
77
91
  files:
78
- - lib/array.rb
79
- - lib/either.rb
80
- - lib/err.rb
81
- - lib/error.rb
82
- - lib/left.rb
83
92
  - lib/monad-oxide.rb
84
- - lib/none.rb
85
- - lib/ok.rb
86
- - lib/option.rb
87
- - lib/result.rb
88
- - lib/right.rb
89
- - lib/some.rb
90
- - lib/version.rb
93
+ - lib/monad-oxide/array.rb
94
+ - lib/monad-oxide/concurrent-promises.rb
95
+ - lib/monad-oxide/either.rb
96
+ - lib/monad-oxide/err.rb
97
+ - lib/monad-oxide/error.rb
98
+ - lib/monad-oxide/left.rb
99
+ - lib/monad-oxide/none.rb
100
+ - lib/monad-oxide/ok.rb
101
+ - lib/monad-oxide/option.rb
102
+ - lib/monad-oxide/result.rb
103
+ - lib/monad-oxide/right.rb
104
+ - lib/monad-oxide/some.rb
105
+ - lib/monad-oxide/version.rb
91
106
  homepage:
92
107
  licenses:
93
108
  - Apache-2.0
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes