monad-oxide 0.17.0 → 0.18.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: 7f4add1af70591ea0b72483b5608bb2c0e08d06d29d2c34dc2d952d501c9f632
4
- data.tar.gz: c7a0d1d2a47c157faf8aa069425e37b11964b9dc81ff6d3329b51dd352350d51
3
+ metadata.gz: ffb60a419ac6559c096b5ed4b548a33c09181526ab2f7f4796468c3a207391d1
4
+ data.tar.gz: 5361aa132d7073416195fda40638a26a0072ff9852226472a3d964525adac17a
5
5
  SHA512:
6
- metadata.gz: 37c193a394b45179137bd13127c0907b9848fb87a116e81e9de5b821aca3e967e5559209861c6da200ea59bc30d35f1b1a8591cca0224a8cc617ccc5e39b3e01
7
- data.tar.gz: fefeeef05166cee8ae902fec3af6e47d848dcacc3da0008bade58d896ca1d9e9846f8f549348b9834d4ba44cd63efa2eb912c4a8b8cbbb2315d9ac3fff035d74
6
+ metadata.gz: 1973d9a47176e3e31ebf8c2e28feab104aaa7b65bdb08c874dd4a0d0c037d74b990b327394eb91965ba5245d78a2060d24bbc458e0b679435003187622c3e94f
7
+ data.tar.gz: b1ac8aebcb9173063d5bcdd25c59bc97bb2d1e36071024006ac3f7e77bbe82672a3710f551541dbb4688eef8088701d5ab391194f3bba667733ca78b44d70379
@@ -2,23 +2,34 @@
2
2
  class Array
3
3
 
4
4
  ##
5
- # Take an Array of Results and convert them to a single Result whose value is
6
- # an Array of Ok or Err values. Ok Results will have only Ok values, and Err
7
- # Results will have only Err values. A single Err in the input Array will
8
- # convert the entire Result into an Err.
5
+ # Converts an Array into a single Result. Returns Ok containing all values
6
+ # if every element succeeds, otherwise returns Err containing _any_ errors.
9
7
  #
10
- # @return [MonadOxide::Result<Array<V>, Array<E>>] A Result whose value is an
11
- # array of all of the Oks or Errs in the Array.
8
+ # Element interpretation:
9
+ # - Ok/Err Results: evaluated for success/failure.
10
+ # - Exceptions: treated as errors.
11
+ # - Other values: treated as successes.
12
+ #
13
+ # @return [MonadOxide::Result<Array<V>, Array<E>>] Ok with all values if
14
+ # all succeed, or Err with all errors if any fail.
12
15
  def into_result()
13
16
  tracker = {
14
17
  oks: [],
15
18
  errs: [],
16
19
  }
17
- self.each do |result|
18
- result.match({
19
- MonadOxide::Ok => ->(x) { tracker[:oks].push(x) },
20
- MonadOxide::Err => ->(e) { tracker[:errs].push(e) },
21
- })
20
+ self.each do |element|
21
+ (
22
+ element.is_a?(MonadOxide::Result) ?
23
+ element :
24
+ (element.is_a?(Exception) ?
25
+ MonadOxide.err(element) :
26
+ MonadOxide.ok(element)
27
+ )
28
+ )
29
+ .match({
30
+ MonadOxide::Ok => ->(x) { tracker[:oks].push(x) },
31
+ MonadOxide::Err => ->(e) { tracker[:errs].push(e) },
32
+ })
22
33
  end
23
34
  tracker[:errs].empty?() ?
24
35
  MonadOxide.ok(tracker[:oks]) :
@@ -5,6 +5,7 @@
5
5
 
6
6
  require 'concurrent/promises'
7
7
  require_relative '../monad-oxide'
8
+ require_relative './array'
8
9
 
9
10
  class Concurrent::Promises::Future
10
11
 
@@ -12,16 +13,27 @@ class Concurrent::Promises::Future
12
13
  # Coerces a Current::Promises::Future into a MonadOxide::Result. This
13
14
  # behavior forces the Future to finalize, and thus is blocking behavior.
14
15
  # A successful Future becomes a MonadOxide::Ok, and a failed Future becomes a
15
- # MonadOxide::Err.
16
+ # MonadOxide::Err. If the Promise returns an Array of Results (either on the
17
+ # Err branch or the Ok branch), flatten them.
16
18
  # @return [MonadOxide::Result<A, E>] A coerced Result from the Future,
17
19
  # containing whatever value the Future was holding.
18
20
  def into_result()
19
21
  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,
22
+ (
23
+ success ? MonadOxide.ok(value) : MonadOxide.err(
24
+ err.nil?() ? value: err,
25
+ )
24
26
  )
27
+ .and_then(->(x) {
28
+ x.respond_to?(:into_result) ?
29
+ x.into_result() :
30
+ MonadOxide.ok(x)
31
+ })
32
+ .or_else(->(x) {
33
+ x.respond_to?(:into_result) ?
34
+ x.into_result() :
35
+ MonadOxide.err(x)
36
+ })
25
37
  end
26
38
 
27
39
  end
@@ -20,14 +20,17 @@ module MonadOxide
20
20
  #
21
21
  # On a cursory search, this is not documented behavior.
22
22
  #
23
- # @param x [Exception|T] The potential Exception to add a backtrace to, if
24
- # it is missing a backtrace.
25
- # @returns [Exception|T] The passed value, with a backtrace added if it is
26
- # an Exception.
23
+ # @param x [Exception] The potential Exception to add a backtrace to, if
24
+ # it is missing a backtrace.
25
+ # @returns [Exception] The passed value, with a backtrace added if it is
26
+ # an Exception. Non-Exceptions are wrapped in an
27
+ # Exception.
27
28
  def self.backtrace_fix(x)
28
- if x.kind_of?(Exception) && x.backtrace.nil?
29
+ if !x.kind_of?(Exception)
30
+ raise StandardError.new(x)
31
+ elsif x.kind_of?(Exception) && x.backtrace.nil?()
29
32
  raise x
30
- else
33
+ else # Must be Exception with a backtrace already.
31
34
  x
32
35
  end
33
36
  rescue => e
@@ -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.17.0'
6
+ VERSION='0.18.0'
7
7
  end
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.17.0
4
+ version: 0.18.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: 2026-02-05 00:00:00.000000000 Z
11
+ date: 2026-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: org-ruby