mona-result 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32cb8667c98ff681514f079fed657c8daa835b7c480f2e28c0524892408c81e7
4
- data.tar.gz: 741a2b69c33f10b9ec8fad3c25aeb49d6b7dd6f9178824819d933f34b2b5db38
3
+ metadata.gz: 74a4d1f256317d8a2675c58dc8c5b52822987f3d7f05473042ce617828c9a78d
4
+ data.tar.gz: 278922b075a71ab08d07756e8b46c8cdafa2b11c390e489c9875d482039664d9
5
5
  SHA512:
6
- metadata.gz: 96e77b201ec66ee70f9aa84ff8b7aba988233c210e5cebb1157832c53f3c116f7ecf12f069dc29c4ae3514ed9f9007a0458e1824c2d3b45263ec7487f9bd0057
7
- data.tar.gz: c359b0d6b6782297c3ebebea9e0d241d7646ccb3c44873c8d087567681ed3fb6ff58d827f6d0af9a97516d57e74410d754b47222c6b895440f9b15133b139faa
6
+ metadata.gz: 8319264ee1391c3244626af638c33b575156b17db884984214d140069cf3ae1f5f28bcbf20b5e222537d24b895a36b75b65e656d74645999d01a6b16153e52d2
7
+ data.tar.gz: 8457dbf1772ac1b536b1026cb1cb241456a2fdb27fbbf22e178937d01816921289e825cb1a0f4172629c305ce23ec4f1c89dcbb16f0d9e71fcaf39d0d85588af
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- ## [0.1.1]
1
+ ## [0.1.2] - 2022-08-09
2
+
3
+ - Fix gemspec links
4
+ - Improve documentation
5
+
6
+ ## [0.1.1] - 2022-08-09
2
7
 
3
8
  - Adds basic documentation
4
9
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mona-result (0.1.1)
4
+ mona-result (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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 :numerator, 10
42
- d.set :divisor, 2
43
- d.set :answer, d[:numerator] / d[:divisor]
44
- end # => #<OK {:numerator=>10, :divisor=>2, :answer=>5}>
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.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Mona
4
4
  module Result
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
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.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: