sorbet-result 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.standard.yml +6 -0
- data/.tool-versions +1 -1
- data/CHANGELOG.md +21 -0
- data/Gemfile +3 -5
- data/Gemfile.lock +79 -64
- data/README.md +25 -2
- data/Rakefile +3 -5
- data/lib/minitest/result_assertions.rb +48 -0
- data/lib/sorbet-result.rb +1 -5
- data/lib/typed/result.rb +199 -7
- data/sorbet/rbi/gems/.gitattributes +1 -0
- data/sorbet/rbi/gems/ast@2.4.2.rbi +1 -0
- data/sorbet/rbi/gems/erubi@1.13.0.rbi +150 -0
- data/sorbet/rbi/gems/{io-console@0.6.0.rbi → io-console@0.7.2.rbi} +1 -0
- data/sorbet/rbi/gems/{json@2.6.3.rbi → json@2.7.5.rbi} +168 -72
- data/sorbet/rbi/gems/language_server-protocol@3.17.0.3.rbi +14238 -0
- data/sorbet/rbi/gems/lint_roller@1.1.0.rbi +240 -0
- data/sorbet/rbi/gems/{minitest@5.18.1.rbi → minitest@5.25.1.rbi} +337 -282
- data/sorbet/rbi/gems/netrc@0.11.0.rbi +1 -0
- data/sorbet/rbi/gems/{parallel@1.23.0.rbi → parallel@1.26.3.rbi} +38 -20
- data/sorbet/rbi/gems/{parser@3.2.2.3.rbi → parser@3.3.5.1.rbi} +663 -2397
- data/sorbet/rbi/gems/prism@1.2.0.rbi +39085 -0
- data/sorbet/rbi/gems/psych@5.1.2.rbi +1732 -0
- data/sorbet/rbi/gems/{racc@1.7.1.rbi → racc@1.8.1.rbi} +37 -36
- data/sorbet/rbi/gems/rainbow@3.1.1.rbi +1 -0
- data/sorbet/rbi/gems/{rake@13.0.6.rbi → rake@13.2.1.rbi} +79 -75
- data/sorbet/rbi/gems/rbi@0.2.1.rbi +4535 -0
- data/sorbet/rbi/gems/{regexp_parser@2.8.1.rbi → regexp_parser@2.9.2.rbi} +190 -167
- data/sorbet/rbi/gems/{reline@0.3.5.rbi → reline@0.5.10.rbi} +1 -0
- data/sorbet/rbi/gems/{rubocop-ast@1.29.0.rbi → rubocop-ast@1.33.1.rbi} +1220 -748
- data/sorbet/rbi/gems/rubocop-performance@1.22.1.rbi +9 -0
- data/sorbet/rbi/gems/rubocop-sorbet@0.7.8.rbi +9 -0
- data/sorbet/rbi/gems/{rubocop@1.52.1.rbi → rubocop@1.66.1.rbi} +6236 -3446
- data/sorbet/rbi/gems/ruby-progressbar@1.13.0.rbi +1 -0
- data/sorbet/rbi/gems/spoom@1.5.0.rbi +4932 -0
- data/sorbet/rbi/gems/standard-custom@1.0.2.rbi +9 -0
- data/sorbet/rbi/gems/standard-performance@1.5.0.rbi +9 -0
- data/sorbet/rbi/gems/standard-sorbet@0.0.2.rbi +53 -0
- data/sorbet/rbi/gems/standard@1.41.1.rbi +926 -0
- data/sorbet/rbi/gems/stringio@3.1.1.rbi +9 -0
- data/sorbet/rbi/gems/{tapioca@0.11.6.rbi → tapioca@0.16.3.rbi} +937 -635
- data/sorbet/rbi/gems/{thor@1.2.2.rbi → thor@1.3.2.rbi} +832 -419
- data/sorbet/rbi/gems/{unicode-display_width@2.4.2.rbi → unicode-display_width@2.6.0.rbi} +1 -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} +431 -271
- data/sorbet/tapioca/config.yml +3 -12
- data/sorbet/tapioca/require.rb +0 -1
- metadata +37 -47
- data/.rubocop.yml +0 -33
- data/lib/typed/failure.rb +0 -81
- data/lib/typed/success.rb +0 -80
- data/sorbet/rbi/gems/diff-lcs@1.5.0.rbi +0 -1083
- data/sorbet/rbi/gems/irb@1.7.0.rbi +0 -342
- data/sorbet/rbi/gems/rbi@0.0.16.rbi +0 -3008
- data/sorbet/rbi/gems/rexml@3.2.5.rbi +0 -4717
- data/sorbet/rbi/gems/rubocop-minitest@0.31.0.rbi +0 -2528
- data/sorbet/rbi/gems/rubocop-rake@0.6.0.rbi +0 -328
- data/sorbet/rbi/gems/rubocop-sorbet@0.7.0.rbi +0 -1043
- data/sorbet/rbi/gems/spoom@1.2.1.rbi +0 -2503
- data/sorbet/rbi/gems/unparser@0.6.8.rbi +0 -4525
- data/sorbet/rbi/gems/zeitwerk@2.6.8.rbi +0 -986
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62795733b699fe9adec850e9584a6c45c47e6fa00daa93cb93221a43ca16b131
|
4
|
+
data.tar.gz: 3b0f4ef2e5fc20e61e88724dc6e6637f254f41ec6394b802896f30861c9a40cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59395f384a03d978f128695fc2cf9c1b79a34b91e0c0aeae0e995b9a3ecc440901ff599112d14d06cab99a92cd0dd82ff8831d7d852255ae9ed5f872a14cc17f
|
7
|
+
data.tar.gz: d536a970dc7c60490c6a106178c1e32ef61cfb816d46405fb389dd62d43e0f5d8ac1e7b6a7097aa73b225d4752ab702bc75bafe25b3f365ba08f7d67c1137e75
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.5
|
data/.standard.yml
ADDED
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby 3.
|
1
|
+
ruby 3.3.5
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,27 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [1.2.0] - 2024-11-03
|
10
|
+
|
11
|
+
### Added
|
12
|
+
|
13
|
+
- Add `Typed::Success(payload)` and `Typed::Failure(error)` convenience method (no more `.new`-ing!)
|
14
|
+
- Add `Typed::Success#==` and `Typed::Failure#==` implementations
|
15
|
+
|
16
|
+
### Removed
|
17
|
+
|
18
|
+
- **POTENTIALLY BREAKING** Remove support for Ruby < 3.1.
|
19
|
+
|
20
|
+
## [1.1.0] - 2024-02-21
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- Add minitest assertions for Results
|
25
|
+
|
26
|
+
### Changed
|
27
|
+
|
28
|
+
- Switched to Standard over using Rubocop directly
|
29
|
+
|
9
30
|
## [1.0.0] - 2023-06-20
|
10
31
|
|
11
32
|
### Removed
|
data/Gemfile
CHANGED
@@ -2,15 +2,13 @@
|
|
2
2
|
|
3
3
|
source "https://rubygems.org"
|
4
4
|
|
5
|
-
# Specify your gem's dependencies in
|
5
|
+
# Specify your gem's dependencies in sorbet-result.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
8
|
group :development do
|
9
9
|
gem "rake"
|
10
|
-
gem "
|
11
|
-
gem "
|
12
|
-
gem "rubocop-rake"
|
13
|
-
gem "rubocop-sorbet"
|
10
|
+
gem "standard"
|
11
|
+
gem "standard-sorbet"
|
14
12
|
gem "sorbet"
|
15
13
|
gem "spoom"
|
16
14
|
gem "tapioca", require: false
|
data/Gemfile.lock
CHANGED
@@ -1,108 +1,123 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sorbet-result (1.
|
4
|
+
sorbet-result (1.2.0)
|
5
5
|
sorbet-runtime (~> 0.5)
|
6
|
-
zeitwerk (~> 2.6)
|
7
6
|
|
8
7
|
GEM
|
9
8
|
remote: https://rubygems.org/
|
10
9
|
specs:
|
11
10
|
ast (2.4.2)
|
12
|
-
debug (1.
|
13
|
-
irb (
|
14
|
-
reline (>= 0.3.
|
15
|
-
|
16
|
-
io-console (0.
|
17
|
-
irb (1.
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
debug (1.9.2)
|
12
|
+
irb (~> 1.10)
|
13
|
+
reline (>= 0.3.8)
|
14
|
+
erubi (1.13.0)
|
15
|
+
io-console (0.7.2)
|
16
|
+
irb (1.14.1)
|
17
|
+
rdoc (>= 4.0.0)
|
18
|
+
reline (>= 0.4.2)
|
19
|
+
json (2.7.5)
|
20
|
+
language_server-protocol (3.17.0.3)
|
21
|
+
lint_roller (1.1.0)
|
22
|
+
minitest (5.25.1)
|
21
23
|
netrc (0.11.0)
|
22
|
-
parallel (1.
|
23
|
-
parser (3.
|
24
|
+
parallel (1.26.3)
|
25
|
+
parser (3.3.5.1)
|
24
26
|
ast (~> 2.4.1)
|
25
27
|
racc
|
26
|
-
|
28
|
+
prism (1.2.0)
|
29
|
+
psych (5.1.2)
|
30
|
+
stringio
|
31
|
+
racc (1.8.1)
|
27
32
|
rainbow (3.1.1)
|
28
|
-
rake (13.
|
29
|
-
rbi (0.
|
30
|
-
|
31
|
-
parser (>= 2.6.4.0)
|
33
|
+
rake (13.2.1)
|
34
|
+
rbi (0.2.1)
|
35
|
+
prism (~> 1.0)
|
32
36
|
sorbet-runtime (>= 0.5.9204)
|
33
|
-
|
34
|
-
|
35
|
-
|
37
|
+
rdoc (6.7.0)
|
38
|
+
psych (>= 4.0.0)
|
39
|
+
regexp_parser (2.9.2)
|
40
|
+
reline (0.5.10)
|
36
41
|
io-console (~> 0.5)
|
37
|
-
|
38
|
-
rubocop (1.52.1)
|
42
|
+
rubocop (1.66.1)
|
39
43
|
json (~> 2.3)
|
44
|
+
language_server-protocol (>= 3.17.0)
|
40
45
|
parallel (~> 1.10)
|
41
|
-
parser (>= 3.
|
46
|
+
parser (>= 3.3.0.2)
|
42
47
|
rainbow (>= 2.2.2, < 4.0)
|
43
|
-
regexp_parser (>=
|
44
|
-
|
45
|
-
rubocop-ast (>= 1.28.0, < 2.0)
|
48
|
+
regexp_parser (>= 2.4, < 3.0)
|
49
|
+
rubocop-ast (>= 1.32.2, < 2.0)
|
46
50
|
ruby-progressbar (~> 1.7)
|
47
51
|
unicode-display_width (>= 2.4.0, < 3.0)
|
48
|
-
rubocop-ast (1.
|
49
|
-
parser (>= 3.
|
50
|
-
rubocop-
|
51
|
-
rubocop (>= 1.
|
52
|
-
|
53
|
-
|
54
|
-
rubocop-sorbet (0.7.0)
|
52
|
+
rubocop-ast (1.33.1)
|
53
|
+
parser (>= 3.3.1.0)
|
54
|
+
rubocop-performance (1.22.1)
|
55
|
+
rubocop (>= 1.48.1, < 2.0)
|
56
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
57
|
+
rubocop-sorbet (0.7.8)
|
55
58
|
rubocop (>= 0.90.0)
|
56
59
|
ruby-progressbar (1.13.0)
|
57
|
-
sorbet (0.5.
|
58
|
-
sorbet-static (= 0.5.
|
59
|
-
sorbet-runtime (0.5.
|
60
|
-
sorbet-static (0.5.
|
61
|
-
sorbet-static (0.5.
|
62
|
-
sorbet-static-and-runtime (0.5.
|
63
|
-
sorbet (= 0.5.
|
64
|
-
sorbet-runtime (= 0.5.
|
65
|
-
spoom (1.
|
66
|
-
|
67
|
-
|
60
|
+
sorbet (0.5.11633)
|
61
|
+
sorbet-static (= 0.5.11633)
|
62
|
+
sorbet-runtime (0.5.11633)
|
63
|
+
sorbet-static (0.5.11633-universal-darwin)
|
64
|
+
sorbet-static (0.5.11633-x86_64-linux)
|
65
|
+
sorbet-static-and-runtime (0.5.11633)
|
66
|
+
sorbet (= 0.5.11633)
|
67
|
+
sorbet-runtime (= 0.5.11633)
|
68
|
+
spoom (1.5.0)
|
69
|
+
erubi (>= 1.10.0)
|
70
|
+
prism (>= 0.28.0)
|
71
|
+
sorbet-static-and-runtime (>= 0.5.10187)
|
68
72
|
thor (>= 0.19.2)
|
69
|
-
|
73
|
+
standard (1.41.1)
|
74
|
+
language_server-protocol (~> 3.17.0.2)
|
75
|
+
lint_roller (~> 1.0)
|
76
|
+
rubocop (~> 1.66.0)
|
77
|
+
standard-custom (~> 1.0.0)
|
78
|
+
standard-performance (~> 1.5)
|
79
|
+
standard-custom (1.0.2)
|
80
|
+
lint_roller (~> 1.0)
|
81
|
+
rubocop (~> 1.50)
|
82
|
+
standard-performance (1.5.0)
|
83
|
+
lint_roller (~> 1.1)
|
84
|
+
rubocop-performance (~> 1.22.0)
|
85
|
+
standard-sorbet (0.0.2)
|
86
|
+
lint_roller (~> 1.1)
|
87
|
+
rubocop-sorbet (~> 0.7.0)
|
88
|
+
stringio (3.1.1)
|
89
|
+
tapioca (0.16.3)
|
70
90
|
bundler (>= 2.2.25)
|
71
91
|
netrc (>= 0.11.0)
|
72
92
|
parallel (>= 1.21.0)
|
73
|
-
rbi (~> 0.
|
74
|
-
sorbet-static-and-runtime (>= 0.5.
|
75
|
-
spoom (
|
93
|
+
rbi (~> 0.2)
|
94
|
+
sorbet-static-and-runtime (>= 0.5.11087)
|
95
|
+
spoom (>= 1.2.0)
|
76
96
|
thor (>= 1.2.0)
|
77
97
|
yard-sorbet
|
78
|
-
thor (1.
|
79
|
-
unicode-display_width (2.
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
yard-sorbet (0.8.1)
|
85
|
-
sorbet-runtime (>= 0.5)
|
86
|
-
yard (>= 0.9)
|
87
|
-
zeitwerk (2.6.8)
|
98
|
+
thor (1.3.2)
|
99
|
+
unicode-display_width (2.6.0)
|
100
|
+
yard (0.9.37)
|
101
|
+
yard-sorbet (0.9.0)
|
102
|
+
sorbet-runtime
|
103
|
+
yard
|
88
104
|
|
89
105
|
PLATFORMS
|
90
106
|
arm64-darwin-22
|
107
|
+
arm64-darwin-23
|
91
108
|
x86_64-linux
|
92
109
|
|
93
110
|
DEPENDENCIES
|
94
111
|
debug
|
95
112
|
minitest
|
96
113
|
rake
|
97
|
-
rubocop
|
98
|
-
rubocop-minitest
|
99
|
-
rubocop-rake
|
100
|
-
rubocop-sorbet
|
101
114
|
sorbet
|
102
115
|
sorbet-result!
|
103
116
|
sorbet-runtime
|
104
117
|
spoom
|
118
|
+
standard
|
119
|
+
standard-sorbet
|
105
120
|
tapioca
|
106
121
|
|
107
122
|
BUNDLED WITH
|
108
|
-
2.
|
123
|
+
2.5.18
|
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
|
@@ -127,6 +127,29 @@ res = retrieve_user(user_id)
|
|
127
127
|
|
128
128
|
If the above chain does not fail, the `puts` statement is never run. If the chain does yield a `Failure`, the `puts` block is executed and the `Failure` is ultimately returned.
|
129
129
|
|
130
|
+
### Testing
|
131
|
+
|
132
|
+
We ship with a few Minitest assertions that can be used to easily verify Results.
|
133
|
+
|
134
|
+
```ruby
|
135
|
+
# test_helper.rb
|
136
|
+
|
137
|
+
require "minitest/result_assertions"
|
138
|
+
# You also need add this to `sorbet/tapioca/require.rb` and rebuild the Minitest gem RBIs
|
139
|
+
|
140
|
+
# *_test.rb
|
141
|
+
|
142
|
+
@success = Typed::Success.new("Test Payload")
|
143
|
+
@failure = Typed::Failure.new("Test Error")
|
144
|
+
|
145
|
+
assert_success(@success)
|
146
|
+
assert_failure(@failure)
|
147
|
+
assert_payload("Test Payload", @success)
|
148
|
+
assert_error("Test Error", @failure)
|
149
|
+
|
150
|
+
# We also have the `refute_*` counterparts
|
151
|
+
```
|
152
|
+
|
130
153
|
## Why use Results?
|
131
154
|
|
132
155
|
Let's say you're working on a method that reaches out to an API and fetches a resource. We hope to get a successful response and continue on in our program, but you can imagine several scenarios where we don't get that response: our authentication could fail, the server could return a 5XX response code, or the resource we were querying could have moved or not exist any more.
|
data/Rakefile
CHANGED
@@ -7,15 +7,13 @@ Minitest::TestTask.create do |t|
|
|
7
7
|
t.test_globs = ["test/**/*_test.rb"]
|
8
8
|
end
|
9
9
|
|
10
|
+
require "standard/rake"
|
11
|
+
|
10
12
|
desc "Test Compiler output"
|
11
13
|
task :compiler do
|
12
14
|
sh "./test/test_type_checker.sh"
|
13
15
|
end
|
14
16
|
|
15
|
-
require "rubocop/rake_task"
|
16
|
-
|
17
|
-
RuboCop::RakeTask.new
|
18
|
-
|
19
17
|
desc "Run tapioca compilers"
|
20
18
|
task :tapioca do
|
21
19
|
sh "bin/tapioca gem"
|
@@ -26,4 +24,4 @@ task :sorbet do
|
|
26
24
|
sh "bundle exec srb tc"
|
27
25
|
end
|
28
26
|
|
29
|
-
task default: %i[
|
27
|
+
task default: %i[standard:fix_unsafely sorbet test compiler]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
3
|
+
require "minitest/assertions"
|
4
|
+
require "sorbet-result"
|
5
|
+
|
6
|
+
module Minitest
|
7
|
+
module Assertions
|
8
|
+
# Fails unless Result is a Success
|
9
|
+
def assert_success(result)
|
10
|
+
assert_kind_of(Typed::Success, result)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Fails unless Result is a Failure
|
14
|
+
def assert_failure(result)
|
15
|
+
assert_kind_of(Typed::Failure, result)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Fails unless exp is equal to payload
|
19
|
+
def assert_payload(exp, result)
|
20
|
+
assert_equal(exp, result.payload)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Fails unless exp is equal to error
|
24
|
+
def assert_error(exp, result)
|
25
|
+
assert_equal(exp, result.error)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Fails if Result is a Success
|
29
|
+
def refute_success(result)
|
30
|
+
refute_kind_of(Typed::Success, result)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Fails if Result is a Failure
|
34
|
+
def refute_failure(result)
|
35
|
+
refute_kind_of(Typed::Failure, result)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Fails if exp is equal to payload
|
39
|
+
def refute_payload(exp, result)
|
40
|
+
refute_equal(exp, result.payload)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Fails if exp is equal to error
|
44
|
+
def refute_error(exp, result)
|
45
|
+
refute_equal(exp, result.error)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/sorbet-result.rb
CHANGED
@@ -4,11 +4,7 @@
|
|
4
4
|
# frozen_string_literal: true
|
5
5
|
|
6
6
|
require "sorbet-runtime"
|
7
|
-
|
7
|
+
require_relative "typed/result"
|
8
8
|
|
9
9
|
# Sorbet-aware namespace to super-charge your projects
|
10
10
|
module Typed; end
|
11
|
-
|
12
|
-
loader = Zeitwerk::Loader.new
|
13
|
-
loader.push_dir("#{__dir__}/typed", namespace: Typed)
|
14
|
-
loader.setup
|
data/lib/typed/result.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
# typed: strict
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require_relative "no_error_on_success_error"
|
5
|
+
require_relative "no_payload_on_failure_error"
|
6
|
+
|
4
7
|
module Typed
|
8
|
+
extend T::Sig
|
9
|
+
|
5
10
|
# A monad representing either a success or a failure. Contains payload and error information as well.
|
6
11
|
class Result
|
7
12
|
extend T::Sig
|
@@ -9,21 +14,26 @@ module Typed
|
|
9
14
|
extend T::Generic
|
10
15
|
|
11
16
|
abstract!
|
17
|
+
sealed!
|
12
18
|
|
13
19
|
Payload = type_member(:out)
|
14
20
|
Error = type_member(:out)
|
15
21
|
|
16
22
|
sig { abstract.returns(T::Boolean) }
|
17
|
-
def success
|
23
|
+
def success?
|
24
|
+
end
|
18
25
|
|
19
26
|
sig { abstract.returns(T::Boolean) }
|
20
|
-
def failure
|
27
|
+
def failure?
|
28
|
+
end
|
21
29
|
|
22
30
|
sig { abstract.returns(Payload) }
|
23
|
-
def payload
|
31
|
+
def payload
|
32
|
+
end
|
24
33
|
|
25
34
|
sig { abstract.returns(Error) }
|
26
|
-
def error
|
35
|
+
def error
|
36
|
+
end
|
27
37
|
|
28
38
|
sig do
|
29
39
|
abstract
|
@@ -31,14 +41,16 @@ module Typed
|
|
31
41
|
.params(_block: T.proc.params(arg0: Payload).returns(Result[T.type_parameter(:U), T.type_parameter(:T)]))
|
32
42
|
.returns(T.any(Result[T.type_parameter(:U), T.type_parameter(:T)], Result[T.type_parameter(:U), Error]))
|
33
43
|
end
|
34
|
-
def and_then(&_block)
|
44
|
+
def and_then(&_block)
|
45
|
+
end
|
35
46
|
|
36
47
|
sig do
|
37
48
|
abstract
|
38
49
|
.params(block: T.proc.params(arg0: Error).void)
|
39
50
|
.returns(T.self_type)
|
40
51
|
end
|
41
|
-
def on_error(&block)
|
52
|
+
def on_error(&block)
|
53
|
+
end
|
42
54
|
|
43
55
|
sig do
|
44
56
|
abstract
|
@@ -46,6 +58,186 @@ module Typed
|
|
46
58
|
.params(value: T.type_parameter(:Fallback))
|
47
59
|
.returns(T.any(Payload, T.type_parameter(:Fallback)))
|
48
60
|
end
|
49
|
-
def payload_or(value)
|
61
|
+
def payload_or(value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Success < Result
|
66
|
+
extend T::Sig
|
67
|
+
extend T::Generic
|
68
|
+
|
69
|
+
Payload = type_member
|
70
|
+
Error = type_member { {fixed: T.noreturn} }
|
71
|
+
|
72
|
+
sig { override.returns(Payload) }
|
73
|
+
attr_reader :payload
|
74
|
+
|
75
|
+
sig do
|
76
|
+
type_parameters(:T)
|
77
|
+
.params(payload: T.type_parameter(:T))
|
78
|
+
.returns(Typed::Success[T.type_parameter(:T)])
|
79
|
+
end
|
80
|
+
def self.new(payload)
|
81
|
+
super
|
82
|
+
end
|
83
|
+
|
84
|
+
sig { returns(Typed::Success[NilClass]) }
|
85
|
+
def self.blank
|
86
|
+
new(nil)
|
87
|
+
end
|
88
|
+
|
89
|
+
sig { params(payload: Payload).void }
|
90
|
+
def initialize(payload)
|
91
|
+
@payload = payload
|
92
|
+
super()
|
93
|
+
end
|
94
|
+
|
95
|
+
sig { override.returns(T::Boolean) }
|
96
|
+
def success?
|
97
|
+
true
|
98
|
+
end
|
99
|
+
|
100
|
+
sig { override.returns(T::Boolean) }
|
101
|
+
def failure?
|
102
|
+
false
|
103
|
+
end
|
104
|
+
|
105
|
+
sig { override.returns(T.noreturn) }
|
106
|
+
def error
|
107
|
+
raise NoErrorOnSuccessError
|
108
|
+
end
|
109
|
+
|
110
|
+
sig do
|
111
|
+
override
|
112
|
+
.type_parameters(:U, :T)
|
113
|
+
.params(block: T.proc.params(arg0: Payload).returns(Result[T.type_parameter(:U), T.type_parameter(:T)]))
|
114
|
+
.returns(Result[T.type_parameter(:U), T.type_parameter(:T)])
|
115
|
+
end
|
116
|
+
def and_then(&block)
|
117
|
+
block.call(payload)
|
118
|
+
end
|
119
|
+
|
120
|
+
sig do
|
121
|
+
override
|
122
|
+
.params(_block: T.proc.params(arg0: Error).void)
|
123
|
+
.returns(T.self_type)
|
124
|
+
end
|
125
|
+
def on_error(&_block)
|
126
|
+
self
|
127
|
+
end
|
128
|
+
|
129
|
+
sig do
|
130
|
+
override
|
131
|
+
.type_parameters(:Fallback)
|
132
|
+
.params(_value: T.type_parameter(:Fallback))
|
133
|
+
.returns(T.any(Payload, T.type_parameter(:Fallback)))
|
134
|
+
end
|
135
|
+
def payload_or(_value)
|
136
|
+
payload
|
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)
|
161
|
+
end
|
162
|
+
|
163
|
+
class Failure < Result
|
164
|
+
extend T::Sig
|
165
|
+
extend T::Generic
|
166
|
+
|
167
|
+
Payload = type_member { {fixed: T.noreturn} }
|
168
|
+
Error = type_member
|
169
|
+
|
170
|
+
sig { override.returns(Error) }
|
171
|
+
attr_reader :error
|
172
|
+
|
173
|
+
sig do
|
174
|
+
type_parameters(:T)
|
175
|
+
.params(error: T.type_parameter(:T))
|
176
|
+
.returns(Typed::Failure[T.type_parameter(:T)])
|
177
|
+
end
|
178
|
+
def self.new(error)
|
179
|
+
super
|
180
|
+
end
|
181
|
+
|
182
|
+
sig { returns(Typed::Failure[NilClass]) }
|
183
|
+
def self.blank
|
184
|
+
new(nil)
|
185
|
+
end
|
186
|
+
|
187
|
+
sig { params(error: Error).void }
|
188
|
+
def initialize(error)
|
189
|
+
@error = error
|
190
|
+
super()
|
191
|
+
end
|
192
|
+
|
193
|
+
sig { override.returns(T::Boolean) }
|
194
|
+
def success?
|
195
|
+
false
|
196
|
+
end
|
197
|
+
|
198
|
+
sig { override.returns(T::Boolean) }
|
199
|
+
def failure?
|
200
|
+
true
|
201
|
+
end
|
202
|
+
|
203
|
+
sig { override.returns(T.noreturn) }
|
204
|
+
def payload
|
205
|
+
raise NoPayloadOnFailureError
|
206
|
+
end
|
207
|
+
|
208
|
+
sig do
|
209
|
+
override
|
210
|
+
.type_parameters(:U, :T)
|
211
|
+
.params(_block: T.proc.params(arg0: Payload).returns(Result[T.type_parameter(:U), T.type_parameter(:T)]))
|
212
|
+
.returns(Result[T.type_parameter(:U), Error])
|
213
|
+
end
|
214
|
+
def and_then(&_block)
|
215
|
+
self
|
216
|
+
end
|
217
|
+
|
218
|
+
sig do
|
219
|
+
override
|
220
|
+
.params(block: T.proc.params(arg0: Error).void)
|
221
|
+
.returns(T.self_type)
|
222
|
+
end
|
223
|
+
def on_error(&block)
|
224
|
+
block.call(error)
|
225
|
+
self
|
226
|
+
end
|
227
|
+
|
228
|
+
sig do
|
229
|
+
override
|
230
|
+
.type_parameters(:Fallback)
|
231
|
+
.params(value: T.type_parameter(:Fallback))
|
232
|
+
.returns(T.any(Payload, T.type_parameter(:Fallback)))
|
233
|
+
end
|
234
|
+
def payload_or(value)
|
235
|
+
value
|
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
|
50
242
|
end
|
51
243
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
**/*.rbi linguist-generated=true
|
@@ -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
|