monad-oxide 0.13.0 → 0.14.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/result.rb +22 -0
  3. data/lib/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f39d28705c0ba38e6cdaff1b0dfbd12468f7f8529d16d51b89b9583d5ddc484d
4
- data.tar.gz: 245f18cb7377cfe3ff4ecee26d553d1bd695daa01ba0919a73218520ce23e980
3
+ metadata.gz: 1f4a3e02d264fe9a27b7e48c58865eacf77db7a083d75d4c6383aa76243d65a9
4
+ data.tar.gz: f422c2b96a295fa4bcfee050d494c43f8ee721dac43d8e609321cfecf2f0020c
5
5
  SHA512:
6
- metadata.gz: a0c170fddf3095ffa876701fdaa799b5385055098e583ad1e82400c183204a9b5801558ead2dd265c8f9fe5eaca42c0e100ee15f9f76adab8e2e7f309fea5aa9
7
- data.tar.gz: 4c82cfb3ae795077dfb14b62e3e9c663edd44cca6fd0b35b24e23d84f4b3fef53f02a0439e668eb0856c2956608e5fe150fe2ab562178e97b843f8aa1139763a
6
+ metadata.gz: 0c146c13f5d0a6867ec4cd0426c2a765c611c6c71b83bb12a5872ef2adc0fea4fb9845b46c9925d0a731722420d1c603afbbb0e72c3890405790c66c9474e249
7
+ data.tar.gz: 0732a70394523cfde5269d72ec6581ff7695bce800aea1cdd86e1c78574b81d419aaa8a38fb2dfde7b5e988673493f03261294b48e18ca37e6c1f22bdbd1c67a
data/lib/result.rb CHANGED
@@ -58,6 +58,28 @@ module MonadOxide
58
58
  # protected :new
59
59
  # end
60
60
 
61
+ class << self
62
+
63
+ ##
64
+ # Convenience for executing arbitrary code and coercing it to a Result.
65
+ # Any exceptions raised coerce it into an Err, and the return value is the
66
+ # value for the Ok.
67
+ # @param f [Proc<Result<A>>] The function to call. Could be a block
68
+ # instead. Takes no arguments and could return any [Object].
69
+ # @yield Will yield a block that takes no arguments A and returns a
70
+ # [Object]. Same as `f' parameter.
71
+ # @return [MonadOxide::Result<A, E>] An Ok if there are no exceptions
72
+ # raised, and an Err with the exception if any exception is raised.
73
+ def try(f=nil, &block)
74
+ begin
75
+ MonadOxide.ok((f || block).call())
76
+ rescue => e
77
+ MonadOxide.err(e)
78
+ end
79
+ end
80
+
81
+ end
82
+
61
83
  def initialize(data)
62
84
  raise NoMethodError.new('Do not use Result directly. See Ok and Err.')
63
85
  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.13.0'
6
+ VERSION='0.14.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.13.0
4
+ version: 0.14.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-03-06 00:00:00.000000000 Z
11
+ date: 2025-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: org-ruby