monad-oxide 0.8.0 → 0.9.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 (6) hide show
  1. checksums.yaml +4 -4
  2. data/lib/err.rb +22 -0
  3. data/lib/ok.rb +22 -0
  4. data/lib/result.rb +25 -11
  5. data/lib/version.rb +1 -1
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c37567d8988443ab1076e07e5784fa454f430a12400acbb15526de2164a2686
4
- data.tar.gz: a09be57539e071b3094b1d052cff724f0b71e8ae22ecd3ed151ffc355984b041
3
+ metadata.gz: d74a96544bd662cb0fcf3131ca119560a4c0811e27a0668b24ef4bca351c610f
4
+ data.tar.gz: d93aa6573dd0bc7ac9529f828b630a421e9d527d1a75b6074fe8879a7defd52e
5
5
  SHA512:
6
- metadata.gz: a0b562a479e20ec1f488fe476c60c1c7138aa62f67b9cb83ca526ce0ff4e97a8c193d75062a175a466e877ae27b163ab9162cf72352126122035aa397024ac88
7
- data.tar.gz: a78393ad99ebe353b9a9ccdbc31756e87a9578e768fa4b47fbef1bd756b08baa131b52ff69129a502d503e40daa44df283b678ec0ac26f5738b3bce562f003c9
6
+ metadata.gz: 793f5483be340bb1e5789fb29488a8c040b803848b5579fbc29e50af13006b1699fa75402bf796ead161031835c246908e7d543c98994c82d43d5a56641d8d43
7
+ data.tar.gz: 998649fd304a9cfe9ce05dea05b67ac88e616a3e4a8a22c707c0ff4661ac5574170a016a5d21bf1c0f610ec5de2543e0817ed71830ea59a8682b6a43e1c51ab1
data/lib/err.rb CHANGED
@@ -65,6 +65,17 @@ module MonadOxide
65
65
  self
66
66
  end
67
67
 
68
+ ##
69
+ # Identifies that this is an `Err`.
70
+ # For counterparts:
71
+ # @see MonadOxide::Ok#ok?
72
+ # @see MonadOxide::Ok#err?
73
+ # @see MonadOxide::Err#ok?
74
+ # @return [Boolean] `true` because this is an `Err`.
75
+ def err?()
76
+ true
77
+ end
78
+
68
79
  ##
69
80
  # Applies `f' or the block over the `Exception' and returns the same `Err'.
70
81
  # No changes are applied. This is ideal for logging. Exceptions raised
@@ -122,6 +133,17 @@ module MonadOxide
122
133
  end
123
134
  end
124
135
 
136
+ ##
137
+ # Identifies that this is not an `Ok`.
138
+ # For counterparts:
139
+ # @see MonadOxide::Ok#ok?
140
+ # @see MonadOxide::Ok#err?
141
+ # @see MonadOxide::Err#err?
142
+ # @return [Boolean] `false` because this is not an `Ok`.
143
+ def ok?()
144
+ false
145
+ end
146
+
125
147
  ##
126
148
  # Invokes `f' or the block with the data and returns the Result returned
127
149
  # from that. Exceptions raised during `f' or the block will return an
data/lib/ok.rb CHANGED
@@ -40,6 +40,17 @@ module MonadOxide
40
40
  end
41
41
  end
42
42
 
43
+ ##
44
+ # Identifies that this is not an `Err`.
45
+ # For counterparts:
46
+ # @see MonadOxide::Ok#ok?
47
+ # @see MonadOxide::Err#ok?
48
+ # @see MonadOxide::Err#err?
49
+ # @return [Boolean] `false` because this is not an `Err`.
50
+ def err?()
51
+ false
52
+ end
53
+
43
54
  ##
44
55
  # Falls through. @see Result#inspect_err for how this is handled in either
45
56
  # Result case, and @see Err.inspect_err for how this is handled in the Err
@@ -96,6 +107,17 @@ module MonadOxide
96
107
  self
97
108
  end
98
109
 
110
+ ##
111
+ # Identifies that this is an `Ok`.
112
+ # For counterparts:
113
+ # @see MonadOxide::Ok#err?
114
+ # @see MonadOxide::Err#ok?
115
+ # @see MonadOxide::Err#err?
116
+ # @return [Boolean] `true` because this is an `Ok`.
117
+ def ok?()
118
+ true
119
+ end
120
+
99
121
  ##
100
122
  # The Err equivalent to Ok#and_then. This is a no-op for Ok. @see
101
123
  # Err#or_else.
data/lib/result.rb CHANGED
@@ -57,17 +57,10 @@ module MonadOxide
57
57
  end
58
58
 
59
59
  ##
60
- # Un-nest this `Result'. This implementation is shared between `Ok' and
61
- # `Err'. In both cases, the structure's data is operated upon.
62
- # @return [Result] If `A' is a `Result' (meaning this `Result` is nested),
63
- # return the inner-most `Result', regardless of the depth of nesting.
64
- # Otherwise return `self'.
65
- def flatten()
66
- if @data.kind_of?(Result)
67
- return @data.flatten()
68
- else
69
- self
70
- end
60
+ # Determine if this is a MonadOxide::Err.
61
+ # @return [Boolean] `true` if this is a MonadOxide::Err, `false` otherwise.
62
+ def err?()
63
+ false
71
64
  end
72
65
 
73
66
  ##
@@ -113,6 +106,20 @@ module MonadOxide
113
106
  Err.new(ResultMethodNotImplementedError.new())
114
107
  end
115
108
 
109
+ ##
110
+ # Un-nest this `Result'. This implementation is shared between `Ok' and
111
+ # `Err'. In both cases, the structure's data is operated upon.
112
+ # @return [Result] If `A' is a `Result' (meaning this `Result` is nested),
113
+ # return the inner-most `Result', regardless of the depth of nesting.
114
+ # Otherwise return `self'.
115
+ def flatten()
116
+ if @data.kind_of?(Result)
117
+ return @data.flatten()
118
+ else
119
+ self
120
+ end
121
+ end
122
+
116
123
  ##
117
124
  # In the case of `Ok', applies `f' or the block over the data and returns
118
125
  # the same `Ok'. No changes are applied. This is ideal for logging. For
@@ -179,6 +186,13 @@ module MonadOxide
179
186
  matcher[self.class].call(@data)
180
187
  end
181
188
 
189
+ ##
190
+ # Determine if this is a MonadOxide::Ok.
191
+ # @return [Boolean] `true` if this is a MonadOxide::Ok, `false` otherwise.
192
+ def ok?()
193
+ false
194
+ end
195
+
182
196
  ##
183
197
  # For `Err', invokes `f' or the block with the data and returns the Result
184
198
  # returned from that. Exceptions raised during `f' or the block will return
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.8.0'
6
+ VERSION='0.9.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.8.0
4
+ version: 0.9.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: 2023-12-17 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: org-ruby