mona-result 0.1.1 → 0.1.2
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/CHANGELOG.md +6 -1
- data/Gemfile.lock +1 -1
- data/README.md +24 -5
- data/lib/mona/result/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74a4d1f256317d8a2675c58dc8c5b52822987f3d7f05473042ce617828c9a78d
|
4
|
+
data.tar.gz: 278922b075a71ab08d07756e8b46c8cdafa2b11c390e489c9875d482039664d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8319264ee1391c3244626af638c33b575156b17db884984214d140069cf3ae1f5f28bcbf20b5e222537d24b895a36b75b65e656d74645999d01a6b16153e52d2
|
7
|
+
data.tar.gz: 8457dbf1772ac1b536b1026cb1cb241456a2fdb27fbbf22e178937d01816921289e825cb1a0f4172629c305ce23ec4f1c89dcbb16f0d9e71fcaf39d0d85588af
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,12 +36,17 @@ failure.failure # => 4
|
|
36
36
|
failure.reason # => :not_prime
|
37
37
|
failure.and_tap { puts "it is #{_1}" }.and_then { _1 * 5 }.value_or { :nope } # => :nope
|
38
38
|
|
39
|
-
# Dict with sequence
|
39
|
+
# Dict with sequence, example using a fictional repository.
|
40
|
+
# #set can take a [Symbol, Symbol] key argument where left is OK key, right is Err key
|
40
41
|
result = Result.dict do |d|
|
41
|
-
d.set :
|
42
|
-
d.set :
|
43
|
-
d.set :
|
44
|
-
end
|
42
|
+
d.set :user, UserRepo.find user_id
|
43
|
+
d.set :input, PostInput.valid(attributes)
|
44
|
+
d.set [:post, :input], PostRepo.create user_id: user_id, **d[:input]
|
45
|
+
end
|
46
|
+
# if find user fails: # => #<Err {:user=>NotFoundError} reason: :not_found, key: :user>
|
47
|
+
# if validation fails: # => #<Err {:user=>User, :input=>PostInput(invalid)} reason: :invalid, key: :input>
|
48
|
+
# if create fails: # => #<Err {:user=>User, :input=>PostInput(db err)} reason: :db_err, key: :input>
|
49
|
+
# if all ok: # => #<OK: {:user=>User, :post=>Post}>
|
45
50
|
|
46
51
|
# Action - a callable sequence
|
47
52
|
divide = Result.action do |x, y|
|
@@ -78,6 +83,20 @@ in err:, reason:, **meta
|
|
78
83
|
end
|
79
84
|
```
|
80
85
|
|
86
|
+
You can also match a result, using similar semantics, the difference from using case/pattern-match is that a
|
87
|
+
`Mona::Result::NoMatchError` is raised, which keeps a reference to the result (which is useful for differentially
|
88
|
+
handling errors in an enclosing scope - not currently possible with ruby's `NoMatchingPatternError` which does not
|
89
|
+
contain any information about the failed match)
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
Mona::Result.match(result) do |on|
|
93
|
+
on.ok { |value| puts "ok" }
|
94
|
+
on.err(key: :x) { |failure, reason, **meta| puts "error with meta :key => :x" }
|
95
|
+
on.err(:invalid) { |failure, reason, **meta| puts "error with reason :invalid" }
|
96
|
+
on.err { |failure, reason, **meta| puts "error" }
|
97
|
+
end
|
98
|
+
```
|
99
|
+
|
81
100
|
## Development
|
82
101
|
|
83
102
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/mona/result/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mona-result
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ian White
|
@@ -35,14 +35,14 @@ files:
|
|
35
35
|
- lib/mona/result/sequence.rb
|
36
36
|
- lib/mona/result/version.rb
|
37
37
|
- sig/mona/result.rbs
|
38
|
-
homepage: https://github.com/mona/mona-result
|
38
|
+
homepage: https://github.com/mona-rb/mona-result
|
39
39
|
licenses:
|
40
40
|
- MIT
|
41
41
|
metadata:
|
42
42
|
rubygems_mfa_required: 'true'
|
43
|
-
homepage_uri: https://github.com/mona/mona-result
|
44
|
-
source_code_uri: https://github.com/mona/mona-result
|
45
|
-
changelog_uri: https://github.com/mona/mona-result/CHANGELOG.md
|
43
|
+
homepage_uri: https://github.com/mona-rb/mona-result
|
44
|
+
source_code_uri: https://github.com/mona-rb/mona-result
|
45
|
+
changelog_uri: https://github.com/mona-rb/mona-result/CHANGELOG.md
|
46
46
|
post_install_message:
|
47
47
|
rdoc_options: []
|
48
48
|
require_paths:
|