dry-monads 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/LICENSE +1 -1
- data/README.md +4 -12
- data/dry-monads.gemspec +9 -12
- data/lib/dry/monads/conversion_stubs.rb +1 -1
- data/lib/dry/monads/do/all.rb +13 -0
- data/lib/dry/monads/errors.rb +1 -1
- data/lib/dry/monads/lazy.rb +14 -19
- data/lib/dry/monads/list.rb +25 -67
- data/lib/dry/monads/maybe.rb +26 -65
- data/lib/dry/monads/registry.rb +4 -8
- data/lib/dry/monads/result/fixed.rb +2 -4
- data/lib/dry/monads/result.rb +22 -62
- data/lib/dry/monads/right_biased.rb +21 -63
- data/lib/dry/monads/task.rb +15 -33
- data/lib/dry/monads/try.rb +7 -19
- data/lib/dry/monads/unit.rb +3 -12
- data/lib/dry/monads/validated.rb +11 -27
- data/lib/dry/monads/version.rb +1 -1
- data/lib/dry/monads.rb +3 -3
- data/lib/json/add/dry/monads/maybe.rb +3 -5
- metadata +10 -57
data/lib/dry/monads/validated.rb
CHANGED
@@ -39,13 +39,11 @@ module Dry
|
|
39
39
|
# Returns self.
|
40
40
|
#
|
41
41
|
# @return [Validated::Valid, Validated::Invalid]
|
42
|
-
def to_monad
|
43
|
-
self
|
44
|
-
end
|
42
|
+
def to_monad = self
|
45
43
|
|
46
44
|
# Bind/flat_map is not implemented
|
47
45
|
#
|
48
|
-
def bind(
|
46
|
+
def bind(...)
|
49
47
|
# See https://typelevel.org/cats/datatypes/validated.html for details on why
|
50
48
|
raise NotImplementedError,
|
51
49
|
"Validated is not a monad because it would violate the monad laws"
|
@@ -65,9 +63,7 @@ module Dry
|
|
65
63
|
# Extracts the value
|
66
64
|
#
|
67
65
|
# @return [Object]
|
68
|
-
def value!
|
69
|
-
@value
|
70
|
-
end
|
66
|
+
def value! = @value
|
71
67
|
|
72
68
|
# Applies another Valid to the stored function
|
73
69
|
#
|
@@ -85,8 +81,8 @@ module Dry
|
|
85
81
|
# @yieldreturn [Validated::Valid,Validated::Invalid]
|
86
82
|
# @return [Validated::Valid,Validated::Invalid]
|
87
83
|
#
|
88
|
-
def apply(val = Undefined, &
|
89
|
-
Undefined.default(val, &
|
84
|
+
def apply(val = Undefined, &)
|
85
|
+
Undefined.default(val, &).fmap(Curry.(value!))
|
90
86
|
end
|
91
87
|
|
92
88
|
# Lifts a block/proc over Valid
|
@@ -107,16 +103,12 @@ module Dry
|
|
107
103
|
# Ignores values and returns self, see {Invalid#alt_map}
|
108
104
|
#
|
109
105
|
# @return [Validated::Valid]
|
110
|
-
def alt_map(_ = nil)
|
111
|
-
self
|
112
|
-
end
|
106
|
+
def alt_map(_ = nil) = self
|
113
107
|
|
114
108
|
# Ignores arguments, returns self
|
115
109
|
#
|
116
110
|
# @return [Validated::Valid]
|
117
|
-
def or(_ = nil)
|
118
|
-
self
|
119
|
-
end
|
111
|
+
def or(_ = nil) = self
|
120
112
|
|
121
113
|
# @return [String]
|
122
114
|
def inspect
|
@@ -193,9 +185,7 @@ module Dry
|
|
193
185
|
# Ignores the passed argument and returns self
|
194
186
|
#
|
195
187
|
# @return [Validated::Invalid]
|
196
|
-
def fmap(_ = nil)
|
197
|
-
self
|
198
|
-
end
|
188
|
+
def fmap(_ = nil) = self
|
199
189
|
|
200
190
|
# Yields the given callable and returns the result
|
201
191
|
#
|
@@ -212,9 +202,7 @@ module Dry
|
|
212
202
|
end
|
213
203
|
|
214
204
|
# @return [String]
|
215
|
-
def inspect
|
216
|
-
"Invalid(#{@error.inspect})"
|
217
|
-
end
|
205
|
+
def inspect = "Invalid(#{@error.inspect})"
|
218
206
|
alias_method :to_s, :inspect
|
219
207
|
|
220
208
|
# @param other [Object]
|
@@ -289,18 +277,14 @@ module Dry
|
|
289
277
|
# Transforms to Validated
|
290
278
|
#
|
291
279
|
# @return [Validated::Valid]
|
292
|
-
def to_validated
|
293
|
-
Validated::Valid.new(value!)
|
294
|
-
end
|
280
|
+
def to_validated = Validated::Valid.new(value!)
|
295
281
|
end
|
296
282
|
|
297
283
|
class Failure < Result
|
298
284
|
# Transforms to Validated
|
299
285
|
#
|
300
286
|
# @return [Validated::Invalid]
|
301
|
-
def to_validated
|
302
|
-
Validated::Invalid.new(failure, trace)
|
303
|
-
end
|
287
|
+
def to_validated = Validated::Invalid.new(failure, trace)
|
304
288
|
end
|
305
289
|
end
|
306
290
|
|
data/lib/dry/monads/version.rb
CHANGED
data/lib/dry/monads.rb
CHANGED
@@ -14,10 +14,10 @@ module Dry
|
|
14
14
|
module Monads
|
15
15
|
# @api private
|
16
16
|
def self.loader
|
17
|
-
@loader ||= Zeitwerk::Loader.new.tap do |loader|
|
18
|
-
root = File.expand_path("..", __dir__)
|
17
|
+
@loader ||= ::Zeitwerk::Loader.new.tap do |loader|
|
18
|
+
root = ::File.expand_path("..", __dir__)
|
19
19
|
loader.tag = "dry-monads"
|
20
|
-
loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-monads.rb")
|
20
|
+
loader.inflector = ::Zeitwerk::GemInflector.new("#{root}/dry-monads.rb")
|
21
21
|
loader.push_dir(root)
|
22
22
|
loader.ignore(
|
23
23
|
"#{root}/dry-monads.rb",
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
-
require "json" unless defined?(
|
3
|
+
require "json" unless defined?(JSON::JSON_LOADED) && JSON::JSON_LOADED
|
4
4
|
|
5
5
|
require "dry/monads"
|
6
6
|
|
@@ -17,7 +17,7 @@ module Dry
|
|
17
17
|
|
18
18
|
# Returns a hash, that will be turned into a JSON object and represent this
|
19
19
|
# object.
|
20
|
-
def as_json(
|
20
|
+
def as_json(*, **)
|
21
21
|
{
|
22
22
|
JSON.create_id => self.class.name,
|
23
23
|
value: none? ? nil : @value
|
@@ -26,9 +26,7 @@ module Dry
|
|
26
26
|
|
27
27
|
# Stores class name (Dry::Monads::Maybe::Some or Dry::Monads::Maybe::None)
|
28
28
|
# with the monad value as JSON string
|
29
|
-
def to_json(...)
|
30
|
-
as_json.to_json(...)
|
31
|
-
end
|
29
|
+
def to_json(...) = as_json.to_json(...)
|
32
30
|
end
|
33
31
|
end
|
34
32
|
end
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nikita Shilnikov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -30,20 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '1.
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '2'
|
33
|
+
version: '1.1'
|
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: '1.
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '2'
|
40
|
+
version: '1.1'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: zeitwerk
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,48 +52,6 @@ dependencies:
|
|
58
52
|
- - "~>"
|
59
53
|
- !ruby/object:Gem::Version
|
60
54
|
version: '2.6'
|
61
|
-
- !ruby/object:Gem::Dependency
|
62
|
-
name: bundler
|
63
|
-
requirement: !ruby/object:Gem::Requirement
|
64
|
-
requirements:
|
65
|
-
- - ">="
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '0'
|
68
|
-
type: :development
|
69
|
-
prerelease: false
|
70
|
-
version_requirements: !ruby/object:Gem::Requirement
|
71
|
-
requirements:
|
72
|
-
- - ">="
|
73
|
-
- !ruby/object:Gem::Version
|
74
|
-
version: '0'
|
75
|
-
- !ruby/object:Gem::Dependency
|
76
|
-
name: rake
|
77
|
-
requirement: !ruby/object:Gem::Requirement
|
78
|
-
requirements:
|
79
|
-
- - ">="
|
80
|
-
- !ruby/object:Gem::Version
|
81
|
-
version: '0'
|
82
|
-
type: :development
|
83
|
-
prerelease: false
|
84
|
-
version_requirements: !ruby/object:Gem::Requirement
|
85
|
-
requirements:
|
86
|
-
- - ">="
|
87
|
-
- !ruby/object:Gem::Version
|
88
|
-
version: '0'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: rspec
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - ">="
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '0'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - ">="
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0'
|
103
55
|
description: Common monads for Ruby
|
104
56
|
email:
|
105
57
|
- fg@flashgordon.ru
|
@@ -144,7 +96,8 @@ metadata:
|
|
144
96
|
changelog_uri: https://github.com/dry-rb/dry-monads/blob/main/CHANGELOG.md
|
145
97
|
source_code_uri: https://github.com/dry-rb/dry-monads
|
146
98
|
bug_tracker_uri: https://github.com/dry-rb/dry-monads/issues
|
147
|
-
|
99
|
+
rubygems_mfa_required: 'true'
|
100
|
+
post_install_message:
|
148
101
|
rdoc_options: []
|
149
102
|
require_paths:
|
150
103
|
- lib
|
@@ -152,15 +105,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
152
105
|
requirements:
|
153
106
|
- - ">="
|
154
107
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
108
|
+
version: 3.1.0
|
156
109
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
110
|
requirements:
|
158
111
|
- - ">="
|
159
112
|
- !ruby/object:Gem::Version
|
160
113
|
version: '0'
|
161
114
|
requirements: []
|
162
|
-
rubygems_version: 3.
|
163
|
-
signing_key:
|
115
|
+
rubygems_version: 3.3.27
|
116
|
+
signing_key:
|
164
117
|
specification_version: 4
|
165
118
|
summary: Common monads for Ruby
|
166
119
|
test_files: []
|