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 +4 -4
- data/lib/monad-oxide/array.rb +22 -11
- data/lib/monad-oxide/concurrent-promises.rb +17 -5
- data/lib/monad-oxide/err.rb +9 -6
- data/lib/monad-oxide/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ffb60a419ac6559c096b5ed4b548a33c09181526ab2f7f4796468c3a207391d1
|
|
4
|
+
data.tar.gz: 5361aa132d7073416195fda40638a26a0072ff9852226472a3d964525adac17a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1973d9a47176e3e31ebf8c2e28feab104aaa7b65bdb08c874dd4a0d0c037d74b990b327394eb91965ba5245d78a2060d24bbc458e0b679435003187622c3e94f
|
|
7
|
+
data.tar.gz: b1ac8aebcb9173063d5bcdd25c59bc97bb2d1e36071024006ac3f7e77bbe82672a3710f551541dbb4688eef8088701d5ab391194f3bba667733ca78b44d70379
|
data/lib/monad-oxide/array.rb
CHANGED
|
@@ -2,23 +2,34 @@
|
|
|
2
2
|
class Array
|
|
3
3
|
|
|
4
4
|
##
|
|
5
|
-
#
|
|
6
|
-
#
|
|
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
|
-
#
|
|
11
|
-
#
|
|
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 |
|
|
18
|
-
|
|
19
|
-
MonadOxide::
|
|
20
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
data/lib/monad-oxide/err.rb
CHANGED
|
@@ -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
|
|
24
|
-
#
|
|
25
|
-
# @returns [Exception
|
|
26
|
-
#
|
|
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
|
|
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
|
data/lib/monad-oxide/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.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.
|
|
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-
|
|
11
|
+
date: 2026-02-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: org-ruby
|