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.
- checksums.yaml +4 -4
- data/lib/err.rb +22 -0
- data/lib/ok.rb +22 -0
- data/lib/result.rb +25 -11
- data/lib/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: d74a96544bd662cb0fcf3131ca119560a4c0811e27a0668b24ef4bca351c610f
|
4
|
+
data.tar.gz: d93aa6573dd0bc7ac9529f828b630a421e9d527d1a75b6074fe8879a7defd52e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
#
|
61
|
-
#
|
62
|
-
|
63
|
-
|
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
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.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:
|
11
|
+
date: 2024-05-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: org-ruby
|