dry-monads 1.3.5 → 1.4.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/CHANGELOG.md +140 -80
- data/LICENSE +1 -1
- data/README.md +5 -4
- data/dry-monads.gemspec +30 -30
- data/lib/dry-monads.rb +1 -1
- data/lib/dry/monads.rb +2 -2
- data/lib/dry/monads/all.rb +2 -2
- data/lib/dry/monads/constants.rb +1 -1
- data/lib/dry/monads/do.rb +52 -18
- data/lib/dry/monads/do/all.rb +36 -17
- data/lib/dry/monads/either.rb +7 -7
- data/lib/dry/monads/errors.rb +5 -2
- data/lib/dry/monads/lazy.rb +15 -4
- data/lib/dry/monads/list.rb +28 -28
- data/lib/dry/monads/maybe.rb +87 -19
- data/lib/dry/monads/registry.rb +10 -10
- data/lib/dry/monads/result.rb +38 -12
- data/lib/dry/monads/result/fixed.rb +33 -24
- data/lib/dry/monads/right_biased.rb +35 -16
- data/lib/dry/monads/task.rb +20 -20
- data/lib/dry/monads/transformer.rb +2 -1
- data/lib/dry/monads/traverse.rb +7 -1
- data/lib/dry/monads/try.rb +45 -12
- data/lib/dry/monads/unit.rb +6 -2
- data/lib/dry/monads/validated.rb +20 -16
- data/lib/dry/monads/version.rb +1 -1
- data/lib/json/add/dry/monads/maybe.rb +3 -3
- metadata +18 -69
- data/.codeclimate.yml +0 -12
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
- data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
- data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
- data/.github/workflows/ci.yml +0 -52
- data/.github/workflows/docsite.yml +0 -34
- data/.github/workflows/sync_configs.yml +0 -56
- data/.gitignore +0 -10
- data/.rspec +0 -4
- data/.rubocop.yml +0 -101
- data/.yardopts +0 -4
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -19
- data/Gemfile.devtools +0 -14
- data/Rakefile +0 -8
- data/bin/.gitkeep +0 -0
- data/bin/console +0 -17
- data/bin/setup +0 -7
- data/docsite/source/case-equality.html.md +0 -42
- data/docsite/source/do-notation.html.md +0 -207
- data/docsite/source/getting-started.html.md +0 -142
- data/docsite/source/index.html.md +0 -179
- data/docsite/source/list.html.md +0 -87
- data/docsite/source/maybe.html.md +0 -146
- data/docsite/source/pattern-matching.html.md +0 -68
- data/docsite/source/result.html.md +0 -190
- data/docsite/source/task.html.md +0 -126
- data/docsite/source/tracing-failures.html.md +0 -32
- data/docsite/source/try.html.md +0 -76
- data/docsite/source/unit.html.md +0 -36
- data/docsite/source/validated.html.md +0 -88
- data/log/.gitkeep +0 -0
- data/project.yml +0 -2
data/lib/dry/monads/validated.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "dry/monads/conversion_stubs"
|
4
|
+
require "dry/monads/constants"
|
5
|
+
require "dry/monads/right_biased"
|
6
6
|
|
7
7
|
module Dry
|
8
8
|
module Monads
|
@@ -51,7 +51,8 @@ module Dry
|
|
51
51
|
#
|
52
52
|
def bind(*)
|
53
53
|
# See https://typelevel.org/cats/datatypes/validated.html for details on why
|
54
|
-
raise NotImplementedError,
|
54
|
+
raise NotImplementedError,
|
55
|
+
"Validated is not a monad because it would violate the monad laws"
|
55
56
|
end
|
56
57
|
|
57
58
|
# Valid result
|
@@ -60,6 +61,8 @@ module Dry
|
|
60
61
|
include Dry::Equalizer(:value!)
|
61
62
|
|
62
63
|
def initialize(value)
|
64
|
+
super()
|
65
|
+
|
63
66
|
@value = value
|
64
67
|
end
|
65
68
|
|
@@ -86,9 +89,8 @@ module Dry
|
|
86
89
|
# @yieldreturn [Validated::Valid,Validated::Invalid]
|
87
90
|
# @return [Validated::Valid,Validated::Invalid]
|
88
91
|
#
|
89
|
-
|
90
|
-
|
91
|
-
Undefined.default(val) { yield }.fmap(Curry.(value!))
|
92
|
+
def apply(val = Undefined, &block)
|
93
|
+
Undefined.default(val, &block).fmap(Curry.(value!))
|
92
94
|
end
|
93
95
|
|
94
96
|
# Lifts a block/proc over Valid
|
@@ -123,7 +125,7 @@ module Dry
|
|
123
125
|
# @return [String]
|
124
126
|
def inspect
|
125
127
|
if Unit.equal?(@value)
|
126
|
-
|
128
|
+
"Valid()"
|
127
129
|
else
|
128
130
|
"Valid(#{@value.inspect})"
|
129
131
|
end
|
@@ -133,7 +135,7 @@ module Dry
|
|
133
135
|
# @param other [Object]
|
134
136
|
# @return [Boolean]
|
135
137
|
def ===(other)
|
136
|
-
self.class
|
138
|
+
other.instance_of?(self.class) && value! === other.value!
|
137
139
|
end
|
138
140
|
end
|
139
141
|
|
@@ -154,6 +156,8 @@ module Dry
|
|
154
156
|
include Dry::Equalizer(:error)
|
155
157
|
|
156
158
|
def initialize(error, trace = RightBiased::Left.trace_caller)
|
159
|
+
super()
|
160
|
+
|
157
161
|
@error = error
|
158
162
|
@trace = trace
|
159
163
|
end
|
@@ -168,9 +172,9 @@ module Dry
|
|
168
172
|
# @yieldreturn [Validated::Valid,Validated::Invalid]
|
169
173
|
# @return [Validated::Invalid]
|
170
174
|
#
|
171
|
-
def apply(val = Undefined)
|
175
|
+
def apply(val = Undefined, &block)
|
172
176
|
Undefined
|
173
|
-
.default(val)
|
177
|
+
.default(val, &block)
|
174
178
|
.alt_map { |v| @error + v }
|
175
179
|
.fmap { return self }
|
176
180
|
end
|
@@ -220,7 +224,7 @@ module Dry
|
|
220
224
|
# @param other [Object]
|
221
225
|
# @return [Boolean]
|
222
226
|
def ===(other)
|
223
|
-
self.class
|
227
|
+
other.instance_of?(self.class) && error === other.error
|
224
228
|
end
|
225
229
|
end
|
226
230
|
|
@@ -250,7 +254,7 @@ module Dry
|
|
250
254
|
#
|
251
255
|
def Valid(value = Undefined, &block)
|
252
256
|
v = Undefined.default(value, block)
|
253
|
-
raise ArgumentError,
|
257
|
+
raise ArgumentError, "No value given" if !value.nil? && v.nil?
|
254
258
|
|
255
259
|
Valid.new(v)
|
256
260
|
end
|
@@ -267,7 +271,7 @@ module Dry
|
|
267
271
|
#
|
268
272
|
def Invalid(value = Undefined, &block)
|
269
273
|
v = Undefined.default(value, block)
|
270
|
-
raise ArgumentError,
|
274
|
+
raise ArgumentError, "No value given" if !value.nil? && v.nil?
|
271
275
|
|
272
276
|
Invalid.new(v, RightBiased::Left.trace_caller)
|
273
277
|
end
|
@@ -297,14 +301,14 @@ module Dry
|
|
297
301
|
class Failure < Result
|
298
302
|
# Transforms to Validated
|
299
303
|
#
|
300
|
-
# @return [Validated::
|
304
|
+
# @return [Validated::Invalid]
|
301
305
|
def to_validated
|
302
306
|
Validated::Invalid.new(failure, trace)
|
303
307
|
end
|
304
308
|
end
|
305
309
|
end
|
306
310
|
|
307
|
-
require
|
311
|
+
require "dry/monads/registry"
|
308
312
|
register_mixin(:validated, Validated::Mixin)
|
309
313
|
end
|
310
314
|
end
|
data/lib/dry/monads/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
require
|
3
|
+
require "json" unless defined?(::JSON::JSON_LOADED) && ::JSON::JSON_LOADED
|
4
4
|
|
5
|
-
require
|
5
|
+
require "dry/monads"
|
6
6
|
|
7
7
|
# Inspired by standard library implementation
|
8
8
|
# for Time serialization/deserialization see (json/lib/json/add/time.rb)
|
@@ -12,7 +12,7 @@ module Dry
|
|
12
12
|
class Maybe
|
13
13
|
# Deserializes JSON string by using Dry::Monads::Maybe#lift method
|
14
14
|
def self.json_create(serialized)
|
15
|
-
coerce(serialized.fetch(
|
15
|
+
coerce(serialized.fetch("value"))
|
16
16
|
end
|
17
17
|
|
18
18
|
# Returns a hash, that will be turned into a JSON object and represent this
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-monads
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
|
-
autorequire:
|
9
|
-
bindir:
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -30,34 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
34
|
-
- - ">="
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: 0.4.4
|
33
|
+
version: '0.7'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
40
37
|
requirements:
|
41
38
|
- - "~>"
|
42
39
|
- !ruby/object:Gem::Version
|
43
|
-
version: '0.
|
44
|
-
- - ">="
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: 0.4.4
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: dry-equalizer
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - ">="
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '0'
|
40
|
+
version: '0.7'
|
61
41
|
- !ruby/object:Gem::Dependency
|
62
42
|
name: bundler
|
63
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,14 +58,14 @@ dependencies:
|
|
78
58
|
requirements:
|
79
59
|
- - ">="
|
80
60
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
61
|
+
version: 0.1.2
|
82
62
|
type: :development
|
83
63
|
prerelease: false
|
84
64
|
version_requirements: !ruby/object:Gem::Requirement
|
85
65
|
requirements:
|
86
66
|
- - ">="
|
87
67
|
- !ruby/object:Gem::Version
|
88
|
-
version:
|
68
|
+
version: 0.1.2
|
89
69
|
- !ruby/object:Gem::Dependency
|
90
70
|
name: rake
|
91
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,48 +94,16 @@ dependencies:
|
|
114
94
|
- - ">="
|
115
95
|
- !ruby/object:Gem::Version
|
116
96
|
version: '0'
|
117
|
-
description: Common monads for Ruby
|
97
|
+
description: Common monads for Ruby
|
118
98
|
email:
|
119
99
|
- fg@flashgordon.ru
|
120
100
|
executables: []
|
121
101
|
extensions: []
|
122
102
|
extra_rdoc_files: []
|
123
103
|
files:
|
124
|
-
- ".codeclimate.yml"
|
125
|
-
- ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
|
126
|
-
- ".github/ISSUE_TEMPLATE/---bug-report.md"
|
127
|
-
- ".github/ISSUE_TEMPLATE/---feature-request.md"
|
128
|
-
- ".github/workflows/ci.yml"
|
129
|
-
- ".github/workflows/docsite.yml"
|
130
|
-
- ".github/workflows/sync_configs.yml"
|
131
|
-
- ".gitignore"
|
132
|
-
- ".rspec"
|
133
|
-
- ".rubocop.yml"
|
134
|
-
- ".yardopts"
|
135
104
|
- CHANGELOG.md
|
136
|
-
- CODE_OF_CONDUCT.md
|
137
|
-
- CONTRIBUTING.md
|
138
|
-
- Gemfile
|
139
|
-
- Gemfile.devtools
|
140
105
|
- LICENSE
|
141
106
|
- README.md
|
142
|
-
- Rakefile
|
143
|
-
- bin/.gitkeep
|
144
|
-
- bin/console
|
145
|
-
- bin/setup
|
146
|
-
- docsite/source/case-equality.html.md
|
147
|
-
- docsite/source/do-notation.html.md
|
148
|
-
- docsite/source/getting-started.html.md
|
149
|
-
- docsite/source/index.html.md
|
150
|
-
- docsite/source/list.html.md
|
151
|
-
- docsite/source/maybe.html.md
|
152
|
-
- docsite/source/pattern-matching.html.md
|
153
|
-
- docsite/source/result.html.md
|
154
|
-
- docsite/source/task.html.md
|
155
|
-
- docsite/source/tracing-failures.html.md
|
156
|
-
- docsite/source/try.html.md
|
157
|
-
- docsite/source/unit.html.md
|
158
|
-
- docsite/source/validated.html.md
|
159
107
|
- dry-monads.gemspec
|
160
108
|
- lib/dry-monads.rb
|
161
109
|
- lib/dry/monads.rb
|
@@ -183,14 +131,15 @@ files:
|
|
183
131
|
- lib/dry/monads/validated.rb
|
184
132
|
- lib/dry/monads/version.rb
|
185
133
|
- lib/json/add/dry/monads/maybe.rb
|
186
|
-
-
|
187
|
-
- project.yml
|
188
|
-
homepage: https://github.com/dry-rb/dry-monads
|
134
|
+
homepage: https://dry-rb.org/gems/dry-monads
|
189
135
|
licenses:
|
190
136
|
- MIT
|
191
137
|
metadata:
|
192
138
|
allowed_push_host: https://rubygems.org
|
193
|
-
|
139
|
+
changelog_uri: https://github.com/dry-rb/dry-monads/blob/master/CHANGELOG.md
|
140
|
+
source_code_uri: https://github.com/dry-rb/dry-monads
|
141
|
+
bug_tracker_uri: https://github.com/dry-rb/dry-monads/issues
|
142
|
+
post_install_message:
|
194
143
|
rdoc_options: []
|
195
144
|
require_paths:
|
196
145
|
- lib
|
@@ -198,15 +147,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
198
147
|
requirements:
|
199
148
|
- - ">="
|
200
149
|
- !ruby/object:Gem::Version
|
201
|
-
version: 2.
|
150
|
+
version: 2.6.0
|
202
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
203
152
|
requirements:
|
204
153
|
- - ">="
|
205
154
|
- !ruby/object:Gem::Version
|
206
155
|
version: '0'
|
207
156
|
requirements: []
|
208
|
-
rubygems_version: 3.
|
209
|
-
signing_key:
|
157
|
+
rubygems_version: 3.2.22
|
158
|
+
signing_key:
|
210
159
|
specification_version: 4
|
211
|
-
summary: Common monads for Ruby
|
160
|
+
summary: Common monads for Ruby
|
212
161
|
test_files: []
|
data/.codeclimate.yml
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: "\U0001F41B Bug report"
|
3
|
-
about: See CONTRIBUTING.md for more information
|
4
|
-
title: ''
|
5
|
-
labels: bug
|
6
|
-
assignees: ''
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
**Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
|
11
|
-
|
12
|
-
For more information see `CONTRIBUTING.md`.
|
13
|
-
|
14
|
-
**Describe the bug**
|
15
|
-
|
16
|
-
A clear and concise description of what the bug is.
|
17
|
-
|
18
|
-
**To Reproduce**
|
19
|
-
|
20
|
-
Provide detailed steps to reproduce, an executable script would be best.
|
21
|
-
|
22
|
-
**Expected behavior**
|
23
|
-
|
24
|
-
A clear and concise description of what you expected to happen.
|
25
|
-
|
26
|
-
**Your environment**
|
27
|
-
|
28
|
-
- Affects my production application: **YES/NO**
|
29
|
-
- Ruby version: ...
|
30
|
-
- OS: ...
|
@@ -1,18 +0,0 @@
|
|
1
|
-
---
|
2
|
-
name: "\U0001F6E0 Feature request"
|
3
|
-
about: See CONTRIBUTING.md for more information
|
4
|
-
title: ''
|
5
|
-
labels: feature
|
6
|
-
assignees: ''
|
7
|
-
|
8
|
-
---
|
9
|
-
|
10
|
-
Summary of what the feature is supposed to do.
|
11
|
-
|
12
|
-
## Examples
|
13
|
-
|
14
|
-
Code examples showing how the feature could be used.
|
15
|
-
|
16
|
-
## Resources
|
17
|
-
|
18
|
-
Additional information, like a link to the discussion forum thread where the feature was discussed etc.
|
data/.github/workflows/ci.yml
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
name: ci
|
4
|
-
|
5
|
-
on:
|
6
|
-
push:
|
7
|
-
paths:
|
8
|
-
- .github/workflows/ci.yml
|
9
|
-
- lib/**
|
10
|
-
- spec/**
|
11
|
-
- Rakefile
|
12
|
-
- Gemfile
|
13
|
-
- Gemfile.devtools
|
14
|
-
- "*.gemspec"
|
15
|
-
- ".rubocop.yml"
|
16
|
-
pull_request:
|
17
|
-
branches:
|
18
|
-
- master
|
19
|
-
|
20
|
-
jobs:
|
21
|
-
tests:
|
22
|
-
runs-on: ubuntu-latest
|
23
|
-
strategy:
|
24
|
-
fail-fast: false
|
25
|
-
matrix:
|
26
|
-
ruby:
|
27
|
-
- "2.7"
|
28
|
-
- "2.6"
|
29
|
-
- "2.5"
|
30
|
-
- "2.4"
|
31
|
-
- "jruby"
|
32
|
-
include:
|
33
|
-
- ruby: "2.6"
|
34
|
-
coverage: "true"
|
35
|
-
steps:
|
36
|
-
- uses: actions/checkout@v1
|
37
|
-
- name: Set up Ruby
|
38
|
-
uses: eregon/use-ruby-action@master
|
39
|
-
with:
|
40
|
-
ruby-version: ${{matrix.ruby}}
|
41
|
-
- name: Install latest bundler
|
42
|
-
run: |
|
43
|
-
gem install bundler
|
44
|
-
bundle config set without 'tools benchmarks docs'
|
45
|
-
- name: Bundle install
|
46
|
-
run: bundle install --jobs 4 --retry 3
|
47
|
-
- name: Run all tests
|
48
|
-
env:
|
49
|
-
COVERAGE: ${{matrix.coverage}}
|
50
|
-
CODACY_RUN_LOCAL: true
|
51
|
-
CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
|
52
|
-
run: bundle exec rake
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# this file is managed by dry-rb/devtools project
|
2
|
-
|
3
|
-
name: docsite
|
4
|
-
|
5
|
-
on:
|
6
|
-
push:
|
7
|
-
paths:
|
8
|
-
- docsite/**
|
9
|
-
- .github/workflows/docsite.yml
|
10
|
-
branches:
|
11
|
-
- master
|
12
|
-
- release-**
|
13
|
-
tags:
|
14
|
-
|
15
|
-
jobs:
|
16
|
-
update-docs:
|
17
|
-
runs-on: ubuntu-latest
|
18
|
-
steps:
|
19
|
-
- uses: actions/checkout@v1
|
20
|
-
- name: Set up Ruby
|
21
|
-
uses: actions/setup-ruby@v1
|
22
|
-
with:
|
23
|
-
ruby-version: "2.6.x"
|
24
|
-
- name: Install dependencies
|
25
|
-
run: |
|
26
|
-
gem install bundler
|
27
|
-
bundle install --jobs 4 --retry 3 --without benchmarks sql
|
28
|
-
- name: Symlink ossy
|
29
|
-
run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
|
30
|
-
- name: Trigger dry-rb.org deploy
|
31
|
-
env:
|
32
|
-
GITHUB_LOGIN: dry-bot
|
33
|
-
GITHUB_TOKEN: ${{ secrets.GH_PAT }}
|
34
|
-
run: bin/ossy github workflow dry-rb/dry-rb.org ci
|