sorbet-result 1.1.0 → 1.3.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/.ruby-version +1 -1
- data/.standard.yml +1 -1
- data/CHANGELOG.md +17 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +85 -68
- data/README.md +4 -4
- data/lib/typed/no_payload_on_failure_error.rb +8 -3
- data/lib/typed/result.rb +33 -3
- data/sorbet/rbi/gems/{ast@2.4.2.rbi → ast@2.4.3.rbi} +4 -3
- data/sorbet/rbi/gems/benchmark@0.4.1.rbi +619 -0
- data/sorbet/rbi/gems/cgi@0.5.0.rbi +2961 -0
- data/sorbet/rbi/gems/date@3.4.1.rbi +75 -0
- data/sorbet/rbi/gems/erb@4.0.4.rbi +910 -0
- data/sorbet/rbi/gems/{erubi@1.12.0.rbi → erubi@1.13.1.rbi} +25 -15
- data/sorbet/rbi/gems/{io-console@0.7.2.rbi → io-console@0.8.0.rbi} +1 -0
- data/sorbet/rbi/gems/{json@2.7.1.rbi → json@2.12.2.rbi} +736 -238
- data/sorbet/rbi/gems/{language_server-protocol@3.17.0.3.rbi → language_server-protocol@3.17.0.5.rbi} +12 -5
- data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +1 -0
- data/sorbet/rbi/gems/logger@1.7.0.rbi +963 -0
- data/sorbet/rbi/gems/{minitest@5.22.2.rbi → minitest@5.25.5.rbi} +326 -308
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +1 -0
- data/sorbet/rbi/gems/{parallel@1.24.0.rbi → parallel@1.27.0.rbi} +32 -21
- data/sorbet/rbi/gems/{parser@3.3.0.5.rbi → parser@3.3.8.0.rbi} +448 -385
- data/sorbet/rbi/gems/pp@0.6.2.rbi +368 -0
- data/sorbet/rbi/gems/prettyprint@0.2.0.rbi +477 -0
- data/sorbet/rbi/gems/prism@1.4.0.rbi +41732 -0
- data/sorbet/rbi/gems/{psych@5.1.2.rbi → psych@5.2.6.rbi} +974 -236
- data/sorbet/rbi/gems/{racc@1.7.3.rbi → racc@1.8.1.rbi} +38 -33
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +1 -0
- data/sorbet/rbi/gems/{rake@13.1.0.rbi → rake@13.3.0.rbi} +62 -58
- data/sorbet/rbi/gems/rbi@0.3.6.rbi +6893 -0
- data/sorbet/rbi/gems/rbs@3.9.4.rbi +6976 -0
- data/sorbet/rbi/gems/{regexp_parser@2.9.0.rbi → regexp_parser@2.10.0.rbi} +196 -172
- data/sorbet/rbi/gems/{reline@0.4.2.rbi → reline@0.6.1.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop-ast@1.30.0.rbi → rubocop-ast@1.45.1.rbi} +1673 -958
- data/sorbet/rbi/gems/{rubocop-performance@1.20.2.rbi → rubocop-performance@1.25.0.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop-sorbet@0.7.7.rbi → rubocop-sorbet@0.9.0.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop@1.60.2.rbi → rubocop@1.75.8.rbi} +9990 -5267
- data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1 -0
- data/sorbet/rbi/gems/spoom@1.6.1.rbi +7274 -0
- data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +1 -0
- data/sorbet/rbi/gems/{standard-performance@1.3.1.rbi → standard-performance@1.8.0.rbi} +1 -0
- data/sorbet/rbi/gems/{standard-sorbet@0.0.2.rbi → standard-sorbet@0.0.3.rbi} +1 -0
- data/sorbet/rbi/gems/{standard@1.34.0.rbi → standard@1.50.0.rbi} +182 -97
- data/sorbet/rbi/gems/{stringio@3.1.0.rbi → stringio@3.1.7.rbi} +1 -0
- data/sorbet/rbi/gems/{tapioca@0.12.0.rbi → tapioca@0.16.11.rbi} +489 -364
- data/sorbet/rbi/gems/{thor@1.3.0.rbi → thor@1.3.2.rbi} +114 -81
- data/sorbet/rbi/gems/unicode-display_width@3.1.4.rbi +132 -0
- data/sorbet/rbi/gems/unicode-emoji@4.0.4.rbi +251 -0
- data/sorbet/rbi/gems/{yard-sorbet@0.8.1.rbi → yard-sorbet@0.9.0.rbi} +36 -29
- data/sorbet/rbi/gems/{yard@0.9.34.rbi → yard@0.9.37.rbi} +430 -270
- metadata +46 -55
- data/.tool-versions +0 -1
- data/sorbet/rbi/gems/prettier_print@1.2.1.rbi +0 -951
- data/sorbet/rbi/gems/prism@0.24.0.rbi +0 -31040
- data/sorbet/rbi/gems/rbi@0.1.9.rbi +0 -3006
- data/sorbet/rbi/gems/rexml@3.2.6.rbi +0 -4781
- data/sorbet/rbi/gems/spoom@1.2.4.rbi +0 -3777
- data/sorbet/rbi/gems/syntax_tree@6.2.0.rbi +0 -23133
- data/sorbet/rbi/gems/unicode-display_width@2.5.0.rbi +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9283d02fabd31c86d614eae2c2cb72aa87f38a4769acff196ac0021460282307
|
4
|
+
data.tar.gz: 74b5fba1a9296cfad0fadae13a7df80e23f45e4ef766a172abdde9ff97e4932f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c59bda910e9a16117f9573426d9fd4a6edd0fc75f03918d3540445d035e9ef6e240a08acfba34c9ba9c25565f9f1287d959af22977b8c8f665cc938b06e116e
|
7
|
+
data.tar.gz: 67ffd89d399ef5b79b2b1752de24fc92d03aaa47f7a455fc40945e11e2f34def317197241f95d1828723059226c7ff630d8a7b69d52b4eb7d0882c06b8f476d1
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.1.4
|
data/.standard.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.3.0] - 2025-06-29
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Added error details to `Typed::NoPayloadOnFailureError` error message
|
14
|
+
|
15
|
+
## [1.2.0] - 2024-11-03
|
16
|
+
|
17
|
+
### Added
|
18
|
+
|
19
|
+
- Add `Typed::Success(payload)` and `Typed::Failure(error)` convenience method (no more `.new`-ing!)
|
20
|
+
- Add `Typed::Success#==` and `Typed::Failure#==` implementations
|
21
|
+
|
22
|
+
### Removed
|
23
|
+
|
24
|
+
- **POTENTIALLY BREAKING** Remove support for Ruby < 3.1.
|
25
|
+
|
9
26
|
## [1.1.0] - 2024-02-21
|
10
27
|
|
11
28
|
### Added
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,111 +1,128 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sorbet-result (1.
|
4
|
+
sorbet-result (1.3.0)
|
5
5
|
sorbet-runtime (~> 0.5)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.4.
|
11
|
-
|
10
|
+
ast (2.4.3)
|
11
|
+
benchmark (0.4.1)
|
12
|
+
cgi (0.5.0)
|
13
|
+
date (3.4.1)
|
14
|
+
debug (1.11.0)
|
12
15
|
irb (~> 1.10)
|
13
16
|
reline (>= 0.3.8)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
17
|
+
erb (4.0.4)
|
18
|
+
cgi (>= 0.3.3)
|
19
|
+
erubi (1.13.1)
|
20
|
+
io-console (0.8.0)
|
21
|
+
irb (1.15.2)
|
22
|
+
pp (>= 0.6.0)
|
23
|
+
rdoc (>= 4.0.0)
|
18
24
|
reline (>= 0.4.2)
|
19
|
-
json (2.
|
20
|
-
language_server-protocol (3.17.0.
|
25
|
+
json (2.12.2)
|
26
|
+
language_server-protocol (3.17.0.5)
|
21
27
|
lint_roller (1.1.0)
|
22
|
-
|
28
|
+
logger (1.7.0)
|
29
|
+
minitest (5.25.5)
|
23
30
|
netrc (0.11.0)
|
24
|
-
parallel (1.
|
25
|
-
parser (3.3.0
|
31
|
+
parallel (1.27.0)
|
32
|
+
parser (3.3.8.0)
|
26
33
|
ast (~> 2.4.1)
|
27
34
|
racc
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
pp (0.6.2)
|
36
|
+
prettyprint
|
37
|
+
prettyprint (0.2.0)
|
38
|
+
prism (1.4.0)
|
39
|
+
psych (5.2.6)
|
40
|
+
date
|
31
41
|
stringio
|
32
|
-
racc (1.
|
42
|
+
racc (1.8.1)
|
33
43
|
rainbow (3.1.1)
|
34
|
-
rake (13.
|
35
|
-
rbi (0.
|
36
|
-
prism (
|
37
|
-
|
38
|
-
|
44
|
+
rake (13.3.0)
|
45
|
+
rbi (0.3.6)
|
46
|
+
prism (~> 1.0)
|
47
|
+
rbs (>= 3.4.4)
|
48
|
+
rbs (3.9.4)
|
49
|
+
logger
|
50
|
+
rdoc (6.14.1)
|
51
|
+
erb
|
39
52
|
psych (>= 4.0.0)
|
40
|
-
regexp_parser (2.
|
41
|
-
reline (0.
|
53
|
+
regexp_parser (2.10.0)
|
54
|
+
reline (0.6.1)
|
42
55
|
io-console (~> 0.5)
|
43
|
-
|
44
|
-
rubocop (1.60.2)
|
56
|
+
rubocop (1.75.8)
|
45
57
|
json (~> 2.3)
|
46
|
-
language_server-protocol (
|
58
|
+
language_server-protocol (~> 3.17.0.2)
|
59
|
+
lint_roller (~> 1.1.0)
|
47
60
|
parallel (~> 1.10)
|
48
61
|
parser (>= 3.3.0.2)
|
49
62
|
rainbow (>= 2.2.2, < 4.0)
|
50
|
-
regexp_parser (>=
|
51
|
-
|
52
|
-
rubocop-ast (>= 1.30.0, < 2.0)
|
63
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
64
|
+
rubocop-ast (>= 1.44.0, < 2.0)
|
53
65
|
ruby-progressbar (~> 1.7)
|
54
|
-
unicode-display_width (>= 2.4.0, <
|
55
|
-
rubocop-ast (1.
|
56
|
-
parser (>= 3.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
rubocop (>=
|
66
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
67
|
+
rubocop-ast (1.45.1)
|
68
|
+
parser (>= 3.3.7.2)
|
69
|
+
prism (~> 1.4)
|
70
|
+
rubocop-performance (1.25.0)
|
71
|
+
lint_roller (~> 1.1)
|
72
|
+
rubocop (>= 1.75.0, < 2.0)
|
73
|
+
rubocop-ast (>= 1.38.0, < 2.0)
|
74
|
+
rubocop-sorbet (0.9.0)
|
75
|
+
lint_roller (~> 1.1)
|
76
|
+
rubocop (>= 1)
|
62
77
|
ruby-progressbar (1.13.0)
|
63
|
-
sorbet (0.5.
|
64
|
-
sorbet-static (= 0.5.
|
65
|
-
sorbet-runtime (0.5.
|
66
|
-
sorbet-static (0.5.
|
67
|
-
sorbet-static (0.5.
|
68
|
-
sorbet-static-and-runtime (0.5.
|
69
|
-
sorbet (= 0.5.
|
70
|
-
sorbet-runtime (= 0.5.
|
71
|
-
spoom (1.
|
78
|
+
sorbet (0.5.12210)
|
79
|
+
sorbet-static (= 0.5.12210)
|
80
|
+
sorbet-runtime (0.5.12210)
|
81
|
+
sorbet-static (0.5.12210-universal-darwin)
|
82
|
+
sorbet-static (0.5.12210-x86_64-linux)
|
83
|
+
sorbet-static-and-runtime (0.5.12210)
|
84
|
+
sorbet (= 0.5.12210)
|
85
|
+
sorbet-runtime (= 0.5.12210)
|
86
|
+
spoom (1.6.1)
|
72
87
|
erubi (>= 1.10.0)
|
88
|
+
prism (>= 0.28.0)
|
89
|
+
rbi (>= 0.2.3)
|
73
90
|
sorbet-static-and-runtime (>= 0.5.10187)
|
74
|
-
syntax_tree (>= 6.1.1)
|
75
91
|
thor (>= 0.19.2)
|
76
|
-
standard (1.
|
92
|
+
standard (1.50.0)
|
77
93
|
language_server-protocol (~> 3.17.0.2)
|
78
94
|
lint_roller (~> 1.0)
|
79
|
-
rubocop (~> 1.
|
95
|
+
rubocop (~> 1.75.5)
|
80
96
|
standard-custom (~> 1.0.0)
|
81
|
-
standard-performance (~> 1.
|
97
|
+
standard-performance (~> 1.8)
|
82
98
|
standard-custom (1.0.2)
|
83
99
|
lint_roller (~> 1.0)
|
84
100
|
rubocop (~> 1.50)
|
85
|
-
standard-performance (1.
|
101
|
+
standard-performance (1.8.0)
|
86
102
|
lint_roller (~> 1.1)
|
87
|
-
rubocop-performance (~> 1.
|
88
|
-
standard-sorbet (0.0.
|
103
|
+
rubocop-performance (~> 1.25.0)
|
104
|
+
standard-sorbet (0.0.3)
|
89
105
|
lint_roller (~> 1.1)
|
90
|
-
rubocop-sorbet (~> 0.
|
91
|
-
stringio (3.1.
|
92
|
-
|
93
|
-
|
94
|
-
tapioca (0.12.0)
|
106
|
+
rubocop-sorbet (~> 0.9.0)
|
107
|
+
stringio (3.1.7)
|
108
|
+
tapioca (0.16.11)
|
109
|
+
benchmark
|
95
110
|
bundler (>= 2.2.25)
|
96
111
|
netrc (>= 0.11.0)
|
97
112
|
parallel (>= 1.21.0)
|
98
|
-
rbi (
|
99
|
-
sorbet-static-and-runtime (>= 0.5.
|
100
|
-
spoom (
|
113
|
+
rbi (~> 0.2)
|
114
|
+
sorbet-static-and-runtime (>= 0.5.11087)
|
115
|
+
spoom (>= 1.2.0)
|
101
116
|
thor (>= 1.2.0)
|
102
117
|
yard-sorbet
|
103
|
-
thor (1.3.
|
104
|
-
unicode-display_width (
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
118
|
+
thor (1.3.2)
|
119
|
+
unicode-display_width (3.1.4)
|
120
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
121
|
+
unicode-emoji (4.0.4)
|
122
|
+
yard (0.9.37)
|
123
|
+
yard-sorbet (0.9.0)
|
124
|
+
sorbet-runtime
|
125
|
+
yard
|
109
126
|
|
110
127
|
PLATFORMS
|
111
128
|
arm64-darwin-22
|
@@ -125,4 +142,4 @@ DEPENDENCIES
|
|
125
142
|
tapioca
|
126
143
|
|
127
144
|
BUNDLED WITH
|
128
|
-
2.4.
|
145
|
+
2.4.22
|
data/README.md
CHANGED
@@ -78,8 +78,8 @@ result = call_api(1)
|
|
78
78
|
|
79
79
|
result.success? # => true on success, false on failure
|
80
80
|
result.failure? # => true on failure, false on success
|
81
|
-
result.payload # =>
|
82
|
-
result.error # =>
|
81
|
+
result.payload # => raises error on failure, payload type on success
|
82
|
+
result.error # => raises error on success, error type on failure
|
83
83
|
result.payload_or("fallback") # => returns payload on success, given value on failure
|
84
84
|
|
85
85
|
# You can combine all the above to write flow-sensitive type-checked code
|
@@ -98,7 +98,7 @@ To do so, use the `#and_then` method to transform the payload of a `Typed::Succe
|
|
98
98
|
|
99
99
|
```ruby
|
100
100
|
# In this example, retrieve_user and send_notification both return a Typed::Result
|
101
|
-
# retrieve_user: Typed::Result[User, RetrieveUserError
|
101
|
+
# retrieve_user: Typed::Result[User, RetrieveUserError]
|
102
102
|
# send_notification: Typed::Result[T::Boolean, SendNotificationError]
|
103
103
|
res = retrieve_user(user_id)
|
104
104
|
.and_then { |user| send_notification(user.email) } # this block will only run if retrieve_user returns a Typed::Success
|
@@ -134,7 +134,7 @@ We ship with a few Minitest assertions that can be used to easily verify Results
|
|
134
134
|
```ruby
|
135
135
|
# test_helper.rb
|
136
136
|
|
137
|
-
require "minitest/
|
137
|
+
require "minitest/result_assertions"
|
138
138
|
# You also need add this to `sorbet/tapioca/require.rb` and rebuild the Minitest gem RBIs
|
139
139
|
|
140
140
|
# *_test.rb
|
@@ -6,9 +6,14 @@ module Typed
|
|
6
6
|
class NoPayloadOnFailureError < StandardError
|
7
7
|
extend T::Sig
|
8
8
|
|
9
|
-
sig { void }
|
10
|
-
def initialize
|
11
|
-
super(
|
9
|
+
sig { params(failure: Failure[T.untyped]).void }
|
10
|
+
def initialize(failure)
|
11
|
+
super(
|
12
|
+
"Attempted to access `payload` from a Failure Result. " \
|
13
|
+
"You were probably expecting a Success Result. " \
|
14
|
+
"Check the result with `#success?` or `#failure?` before attempting to access `payload`. " \
|
15
|
+
"Error encountered: #{failure.error.inspect}"
|
16
|
+
)
|
12
17
|
end
|
13
18
|
end
|
14
19
|
end
|
data/lib/typed/result.rb
CHANGED
@@ -5,6 +5,8 @@ require_relative "no_error_on_success_error"
|
|
5
5
|
require_relative "no_payload_on_failure_error"
|
6
6
|
|
7
7
|
module Typed
|
8
|
+
extend T::Sig
|
9
|
+
|
8
10
|
# A monad representing either a success or a failure. Contains payload and error information as well.
|
9
11
|
class Result
|
10
12
|
extend T::Sig
|
@@ -76,7 +78,7 @@ module Typed
|
|
76
78
|
.returns(Typed::Success[T.type_parameter(:T)])
|
77
79
|
end
|
78
80
|
def self.new(payload)
|
79
|
-
super
|
81
|
+
super
|
80
82
|
end
|
81
83
|
|
82
84
|
sig { returns(Typed::Success[NilClass]) }
|
@@ -133,6 +135,29 @@ module Typed
|
|
133
135
|
def payload_or(_value)
|
134
136
|
payload
|
135
137
|
end
|
138
|
+
|
139
|
+
sig { params(other: T.untyped).returns(T::Boolean) }
|
140
|
+
def ==(other)
|
141
|
+
other.is_a?(Success) && other.payload == payload
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
sig do
|
146
|
+
type_parameters(:T)
|
147
|
+
.params(payload: T.type_parameter(:T))
|
148
|
+
.returns(Typed::Success[T.type_parameter(:T)])
|
149
|
+
end
|
150
|
+
def self.Success(payload)
|
151
|
+
Success.new(payload)
|
152
|
+
end
|
153
|
+
|
154
|
+
sig do
|
155
|
+
type_parameters(:T)
|
156
|
+
.params(error: T.type_parameter(:T))
|
157
|
+
.returns(Typed::Failure[T.type_parameter(:T)])
|
158
|
+
end
|
159
|
+
def self.Failure(error)
|
160
|
+
Failure.new(error)
|
136
161
|
end
|
137
162
|
|
138
163
|
class Failure < Result
|
@@ -151,7 +176,7 @@ module Typed
|
|
151
176
|
.returns(Typed::Failure[T.type_parameter(:T)])
|
152
177
|
end
|
153
178
|
def self.new(error)
|
154
|
-
super
|
179
|
+
super
|
155
180
|
end
|
156
181
|
|
157
182
|
sig { returns(Typed::Failure[NilClass]) }
|
@@ -177,7 +202,7 @@ module Typed
|
|
177
202
|
|
178
203
|
sig { override.returns(T.noreturn) }
|
179
204
|
def payload
|
180
|
-
raise NoPayloadOnFailureError
|
205
|
+
raise NoPayloadOnFailureError.new(self)
|
181
206
|
end
|
182
207
|
|
183
208
|
sig do
|
@@ -209,5 +234,10 @@ module Typed
|
|
209
234
|
def payload_or(value)
|
210
235
|
value
|
211
236
|
end
|
237
|
+
|
238
|
+
sig { params(other: T.untyped).returns(T::Boolean) }
|
239
|
+
def ==(other)
|
240
|
+
other.is_a?(Failure) && other.error == error
|
241
|
+
end
|
212
242
|
end
|
213
243
|
end
|
@@ -4,6 +4,7 @@
|
|
4
4
|
# This is an autogenerated file for types exported from the `ast` gem.
|
5
5
|
# Please instead update this file by running `bin/tapioca gem ast`.
|
6
6
|
|
7
|
+
|
7
8
|
# {AST} is a library for manipulating abstract syntax trees.
|
8
9
|
#
|
9
10
|
# It embraces immutability; each AST node is inherently frozen at
|
@@ -159,7 +160,7 @@ class AST::Node
|
|
159
160
|
|
160
161
|
# Returns the precomputed hash value for this node
|
161
162
|
#
|
162
|
-
# @return [
|
163
|
+
# @return [Integer]
|
163
164
|
#
|
164
165
|
# source://ast//lib/ast/node.rb#61
|
165
166
|
def hash; end
|
@@ -556,8 +557,8 @@ end
|
|
556
557
|
# to define deeply nested ASTs from Ruby code, for example, in
|
557
558
|
# tests. It should be used like this:
|
558
559
|
#
|
559
|
-
# describe YourLanguage
|
560
|
-
# include Sexp
|
560
|
+
# describe YourLanguage do
|
561
|
+
# include ::AST::Sexp
|
561
562
|
#
|
562
563
|
# it "should correctly parse expressions" do
|
563
564
|
# YourLanguage.parse("1 + 2 * 3").should ==
|