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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c3b21d3e3072a7a21013aa3fc863b50e1aca7707122980adcc5313bff792743
|
4
|
+
data.tar.gz: 9b3df76a0c3ce66eb88e8e1bf6b66804f43268b56cb407310944ca7e51614469
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4056e685a4f47e8168fc97ddb4d773ad5f257d9fcc9d484e35221016961ccb525c475b0f20a9ac48ea7f7a14bfbd6ebe98b4672d7695c687efb3ffd8ebd6244b
|
7
|
+
data.tar.gz: 28740b0f45b4e782b9def280eb1f527ce2d970a901d60d883129c31338e481ebb9190836ceb63330e555958a873185d9ae6ad869edd22ab3623975564328d30f
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.7.0 2025-01-07
|
4
|
+
|
5
|
+
|
6
|
+
### Fixed
|
7
|
+
|
8
|
+
- Fix pattern matching for `Try` values (@alexkalderimis)
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Set 3.1 as minimum Ruby version (@flash-gordon)
|
13
|
+
|
14
|
+
[Compare v1.6.0...v1.7.0](https://github.com/dry-rb/dry-monads/compare/v1.6.0...v1.7.0)
|
15
|
+
|
3
16
|
## 1.6.0 2022-11-04
|
4
17
|
|
5
18
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,21 @@
|
|
1
1
|
<!--- this file is synced from dry-rb/template-gem project -->
|
2
2
|
[gem]: https://rubygems.org/gems/dry-monads
|
3
3
|
[actions]: https://github.com/dry-rb/dry-monads/actions
|
4
|
-
[codacy]: https://www.codacy.com/gh/dry-rb/dry-monads
|
5
|
-
[chat]: https://dry-rb.zulipchat.com
|
6
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-monads
|
7
4
|
|
8
|
-
# dry-monads [![
|
9
|
-
|
10
|
-
[![Gem Version](https://badge.fury.io/rb/dry-monads.svg)][gem]
|
11
|
-
[![CI Status](https://github.com/dry-rb/dry-monads/workflows/ci/badge.svg)][actions]
|
12
|
-
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f2eed41bf7f04b38b0a7691c2cf6e73c)][codacy]
|
13
|
-
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f2eed41bf7f04b38b0a7691c2cf6e73c)][codacy]
|
14
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-monads.svg?branch=main)][inchpages]
|
5
|
+
# dry-monads [![Gem Version](https://badge.fury.io/rb/dry-monads.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-monads/workflows/CI/badge.svg)][actions]
|
15
6
|
|
16
7
|
## Links
|
17
8
|
|
18
9
|
* [User documentation](https://dry-rb.org/gems/dry-monads)
|
19
10
|
* [API documentation](http://rubydoc.info/gems/dry-monads)
|
11
|
+
* [Forum](https://discourse.dry-rb.org)
|
20
12
|
|
21
13
|
## Supported Ruby versions
|
22
14
|
|
23
15
|
This library officially supports the following Ruby versions:
|
24
16
|
|
25
|
-
* MRI `>=
|
26
|
-
* jruby `>= 9.
|
17
|
+
* MRI `>= 3.1`
|
18
|
+
* jruby `>= 9.4` (not tested on CI)
|
27
19
|
|
28
20
|
## License
|
29
21
|
|
data/dry-monads.gemspec
CHANGED
@@ -21,19 +21,16 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.executables = []
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
|
24
|
-
spec.metadata["allowed_push_host"]
|
25
|
-
spec.metadata["changelog_uri"]
|
26
|
-
spec.metadata["source_code_uri"]
|
27
|
-
spec.metadata["bug_tracker_uri"]
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-monads/blob/main/CHANGELOG.md"
|
26
|
+
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-monads"
|
27
|
+
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-monads/issues"
|
28
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
28
29
|
|
29
|
-
spec.required_ruby_version = ">=
|
30
|
+
spec.required_ruby_version = ">= 3.1.0"
|
30
31
|
|
31
32
|
# to update dependencies edit project.yml
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
spec.
|
35
|
-
|
36
|
-
spec.add_development_dependency "bundler"
|
37
|
-
spec.add_development_dependency "rake"
|
38
|
-
spec.add_development_dependency "rspec"
|
33
|
+
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
34
|
+
spec.add_dependency "dry-core", "~> 1.1"
|
35
|
+
spec.add_dependency "zeitwerk", "~> 2.6"
|
39
36
|
end
|
data/lib/dry/monads/do/all.rb
CHANGED
@@ -153,5 +153,18 @@ module Dry
|
|
153
153
|
|
154
154
|
require "dry/monads/registry"
|
155
155
|
register_mixin(:do, Do::All)
|
156
|
+
|
157
|
+
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("3.4.0")
|
158
|
+
::Warning.singleton_class.prepend(::Module.new {
|
159
|
+
def warn(message, category: nil)
|
160
|
+
if message.include?("lib/dry/monads/do.rb") &&
|
161
|
+
message.include?("warning: the block passed to")
|
162
|
+
nil
|
163
|
+
else
|
164
|
+
super
|
165
|
+
end
|
166
|
+
end
|
167
|
+
})
|
168
|
+
end
|
156
169
|
end
|
157
170
|
end
|
data/lib/dry/monads/errors.rb
CHANGED
@@ -23,7 +23,7 @@ module Dry
|
|
23
23
|
class ConstructorNotAppliedError < ::NoMethodError
|
24
24
|
def initialize(method_name, constructor_name)
|
25
25
|
super(
|
26
|
-
"For calling .#{method_name} on #{constructor_name}() build a value "\
|
26
|
+
"For calling .#{method_name} on #{constructor_name}() build a value " \
|
27
27
|
"by appending parens: #{constructor_name}()"
|
28
28
|
)
|
29
29
|
end
|
data/lib/dry/monads/lazy.rb
CHANGED
@@ -13,11 +13,11 @@ module Dry
|
|
13
13
|
|
14
14
|
class << self
|
15
15
|
# @private
|
16
|
-
def new(promise = nil, &
|
16
|
+
def new(promise = nil, &)
|
17
17
|
if promise
|
18
18
|
super(promise)
|
19
19
|
else
|
20
|
-
super(Concurrent::Promise.new(executor: :immediate, &
|
20
|
+
super(Concurrent::Promise.new(executor: :immediate, &))
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -27,9 +27,7 @@ module Dry
|
|
27
27
|
# Forces the compution and returns its value.
|
28
28
|
#
|
29
29
|
# @return [Object]
|
30
|
-
def value!
|
31
|
-
@promise.execute.value!
|
32
|
-
end
|
30
|
+
def value! = @promise.execute.value!
|
33
31
|
alias_method :force!, :value!
|
34
32
|
|
35
33
|
# Forces the computation. Note that if the computation
|
@@ -42,23 +40,22 @@ module Dry
|
|
42
40
|
end
|
43
41
|
|
44
42
|
# @return [Boolean]
|
45
|
-
def evaluated?
|
46
|
-
@promise.complete?
|
47
|
-
end
|
43
|
+
def evaluated? = @promise.complete?
|
48
44
|
deprecate :complete?, :evaluated?
|
49
45
|
|
50
46
|
undef_method :wait
|
51
47
|
|
52
48
|
# @return [String]
|
53
49
|
def to_s
|
54
|
-
state =
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
50
|
+
state =
|
51
|
+
case promise.state
|
52
|
+
when :fulfilled
|
53
|
+
value!.inspect
|
54
|
+
when :rejected
|
55
|
+
"!#{promise.reason.inspect}"
|
56
|
+
else
|
57
|
+
"?"
|
58
|
+
end
|
62
59
|
|
63
60
|
"Lazy(#{state})"
|
64
61
|
end
|
@@ -79,9 +76,7 @@ module Dry
|
|
79
76
|
#
|
80
77
|
# @param block [Proc]
|
81
78
|
# @return [Lazy]
|
82
|
-
def Lazy(&
|
83
|
-
Lazy.new(&block)
|
84
|
-
end
|
79
|
+
def Lazy(&) = Lazy.new(&)
|
85
80
|
end
|
86
81
|
|
87
82
|
include Constructors
|
data/lib/dry/monads/list.rb
CHANGED
@@ -9,9 +9,7 @@ module Dry
|
|
9
9
|
#
|
10
10
|
# @param values [Array<Object>] List elements
|
11
11
|
# @return [List]
|
12
|
-
def [](*values)
|
13
|
-
new(values)
|
14
|
-
end
|
12
|
+
def [](*values) = new(values)
|
15
13
|
|
16
14
|
# Coerces a value to a list. `nil` will be coerced to an empty list.
|
17
15
|
#
|
@@ -144,9 +142,7 @@ module Dry
|
|
144
142
|
#
|
145
143
|
# @param other [List] Other list
|
146
144
|
# @return [List]
|
147
|
-
def +(other)
|
148
|
-
List.new(to_ary + other.to_ary)
|
149
|
-
end
|
145
|
+
def +(other) = List.new(to_ary + other.to_ary)
|
150
146
|
|
151
147
|
# Returns a string representation of the list.
|
152
148
|
#
|
@@ -167,24 +163,18 @@ module Dry
|
|
167
163
|
# Returns the first element.
|
168
164
|
#
|
169
165
|
# @return [Object]
|
170
|
-
def first
|
171
|
-
value.first
|
172
|
-
end
|
166
|
+
def first = value.first
|
173
167
|
|
174
168
|
# Returns the last element.
|
175
169
|
#
|
176
170
|
# @return [Object]
|
177
|
-
def last
|
178
|
-
value.last
|
179
|
-
end
|
171
|
+
def last = value.last
|
180
172
|
|
181
173
|
# Folds the list from the left.
|
182
174
|
#
|
183
175
|
# @param initial [Object] Initial value
|
184
176
|
# @return [Object]
|
185
|
-
def fold_left(initial, &
|
186
|
-
value.reduce(initial, &block)
|
187
|
-
end
|
177
|
+
def fold_left(initial, &) = value.reduce(initial, &)
|
188
178
|
alias_method :foldl, :fold_left
|
189
179
|
alias_method :reduce, :fold_left
|
190
180
|
|
@@ -200,52 +190,38 @@ module Dry
|
|
200
190
|
# Whether the list is empty.
|
201
191
|
#
|
202
192
|
# @return [TrueClass, FalseClass]
|
203
|
-
def empty?
|
204
|
-
value.empty?
|
205
|
-
end
|
193
|
+
def empty? = value.empty?
|
206
194
|
|
207
195
|
# Sorts the list.
|
208
196
|
#
|
209
197
|
# @return [List]
|
210
|
-
def sort
|
211
|
-
coerce(value.sort)
|
212
|
-
end
|
198
|
+
def sort = coerce(value.sort)
|
213
199
|
|
214
200
|
# Filters elements with a block
|
215
201
|
#
|
216
202
|
# @return [List]
|
217
|
-
def filter(&
|
218
|
-
coerce(value.select(&block))
|
219
|
-
end
|
203
|
+
def filter(&) = coerce(value.select(&))
|
220
204
|
alias_method :select, :filter
|
221
205
|
|
222
206
|
# List size.
|
223
207
|
#
|
224
208
|
# @return [Integer]
|
225
|
-
def size
|
226
|
-
value.size
|
227
|
-
end
|
209
|
+
def size = value.size
|
228
210
|
|
229
211
|
# Reverses the list.
|
230
212
|
#
|
231
213
|
# @return [List]
|
232
|
-
def reverse
|
233
|
-
coerce(value.reverse)
|
234
|
-
end
|
214
|
+
def reverse = coerce(value.reverse)
|
235
215
|
|
236
216
|
# Returns the first element wrapped with a `Maybe`.
|
237
217
|
#
|
238
218
|
# @return [Maybe<Object>]
|
239
|
-
def head
|
240
|
-
Monads::Maybe.coerce(value.first)
|
241
|
-
end
|
219
|
+
def head = Monads::Maybe.coerce(value.first)
|
242
220
|
|
243
221
|
# Returns list's tail.
|
244
222
|
#
|
245
223
|
# @return [List]
|
246
|
-
def tail
|
247
|
-
coerce(value.drop(1))
|
248
|
-
end
|
224
|
+
def tail = coerce(value.drop(1))
|
249
225
|
|
250
226
|
# Turns the list into a typed one.
|
251
227
|
# Type is required for some operations like .traverse.
|
@@ -258,8 +234,8 @@ module Dry
|
|
258
234
|
raise ArgumentError, "Cannot infer a monad for an empty list"
|
259
235
|
else
|
260
236
|
self.class.warn(
|
261
|
-
"Automatic monad inference is deprecated, pass a type explicitly "\
|
262
|
-
"or use a predefined constant, e.g. List::Result\n"\
|
237
|
+
"Automatic monad inference is deprecated, pass a type explicitly " \
|
238
|
+
"or use a predefined constant, e.g. List::Result\n" \
|
263
239
|
"#{caller.find { _1 !~ %r{(lib/dry/monads)|(gems)} }}"
|
264
240
|
)
|
265
241
|
self.class.new(value, value[0].monad)
|
@@ -272,9 +248,7 @@ module Dry
|
|
272
248
|
# Whether the list is types
|
273
249
|
#
|
274
250
|
# @return [Boolean]
|
275
|
-
def typed?
|
276
|
-
!type.nil?
|
277
|
-
end
|
251
|
+
def typed? = !type.nil?
|
278
252
|
|
279
253
|
# Traverses the list with a block (or without it).
|
280
254
|
# This methods "flips" List structure with the given monad (obtained from the type).
|
@@ -305,24 +279,20 @@ module Dry
|
|
305
279
|
#
|
306
280
|
# @param list [List]
|
307
281
|
# @return [List]
|
308
|
-
def apply(list = Undefined, &
|
309
|
-
v = Undefined.default(list, &
|
282
|
+
def apply(list = Undefined, &)
|
283
|
+
v = Undefined.default(list, &)
|
310
284
|
fmap(Curry).bind { |f| v.fmap { f.(_1) } }
|
311
285
|
end
|
312
286
|
|
313
287
|
# Returns the List monad.
|
314
288
|
#
|
315
289
|
# @return [Monad]
|
316
|
-
def monad
|
317
|
-
List
|
318
|
-
end
|
290
|
+
def monad = List
|
319
291
|
|
320
292
|
# Returns self.
|
321
293
|
#
|
322
294
|
# @return [List]
|
323
|
-
def to_monad
|
324
|
-
self
|
325
|
-
end
|
295
|
+
def to_monad = self
|
326
296
|
|
327
297
|
# Iterates over the list and collects Some values.
|
328
298
|
#
|
@@ -367,15 +337,11 @@ module Dry
|
|
367
337
|
# end
|
368
338
|
#
|
369
339
|
# @api private
|
370
|
-
def deconstruct
|
371
|
-
value
|
372
|
-
end
|
340
|
+
def deconstruct = value
|
373
341
|
|
374
342
|
private
|
375
343
|
|
376
|
-
def coerce(other)
|
377
|
-
self.class.coerce(other)
|
378
|
-
end
|
344
|
+
def coerce(other) = self.class.coerce(other)
|
379
345
|
|
380
346
|
# Empty list
|
381
347
|
EMPTY = List.new([].freeze).freeze
|
@@ -388,17 +354,11 @@ module Dry
|
|
388
354
|
|
389
355
|
attr_reader :type
|
390
356
|
|
391
|
-
def initialize(type)
|
392
|
-
@type = type
|
393
|
-
end
|
357
|
+
def initialize(type) = @type = type
|
394
358
|
|
395
|
-
def [](*args)
|
396
|
-
List.new(args, type)
|
397
|
-
end
|
359
|
+
def [](*args) = List.new(args, type)
|
398
360
|
|
399
|
-
def coerce(value)
|
400
|
-
List.coerce(value, type)
|
401
|
-
end
|
361
|
+
def coerce(value) = List.coerce(value, type)
|
402
362
|
|
403
363
|
def pure(val = Undefined, &block)
|
404
364
|
value = Undefined.default(val, block)
|
@@ -433,9 +393,7 @@ module Dry
|
|
433
393
|
|
434
394
|
# List constructor.
|
435
395
|
# @return [List]
|
436
|
-
def List(value)
|
437
|
-
List.coerce(value)
|
438
|
-
end
|
396
|
+
def List(value) = List.coerce(value)
|
439
397
|
end
|
440
398
|
end
|
441
399
|
|
data/lib/dry/monads/maybe.rb
CHANGED
@@ -46,38 +46,28 @@ module Dry
|
|
46
46
|
end
|
47
47
|
|
48
48
|
# Returns true for an instance of a {Maybe::None} monad.
|
49
|
-
def none?
|
50
|
-
is_a?(None)
|
51
|
-
end
|
49
|
+
def none? = is_a?(None)
|
52
50
|
alias_method :failure?, :none?
|
53
51
|
|
54
52
|
# Returns true for an instance of a {Maybe::Some} monad.
|
55
|
-
def some?
|
56
|
-
is_a?(Some)
|
57
|
-
end
|
53
|
+
def some? = is_a?(Some)
|
58
54
|
alias_method :success?, :some?
|
59
55
|
|
60
56
|
# Returns self, added to keep the interface compatible with that of Either monad types.
|
61
57
|
#
|
62
58
|
# @return [Maybe::Some, Maybe::None]
|
63
|
-
def to_maybe
|
64
|
-
self
|
65
|
-
end
|
59
|
+
def to_maybe = self
|
66
60
|
|
67
61
|
# Returns self.
|
68
62
|
#
|
69
63
|
# @return [Maybe::Some, Maybe::None]
|
70
|
-
def to_monad
|
71
|
-
self
|
72
|
-
end
|
64
|
+
def to_monad = self
|
73
65
|
|
74
66
|
# Returns the Maybe monad.
|
75
67
|
# This is how we're doing polymorphism in Ruby 😕
|
76
68
|
#
|
77
69
|
# @return [Monad]
|
78
|
-
def monad
|
79
|
-
Maybe
|
80
|
-
end
|
70
|
+
def monad = Maybe
|
81
71
|
|
82
72
|
# Represents a value that is present, i.e. not nil.
|
83
73
|
#
|
@@ -96,9 +86,7 @@ module Dry
|
|
96
86
|
# end
|
97
87
|
#
|
98
88
|
# @api public
|
99
|
-
def self.[](*value)
|
100
|
-
new(value)
|
101
|
-
end
|
89
|
+
def self.[](*value) = new(value)
|
102
90
|
|
103
91
|
def initialize(value = Undefined)
|
104
92
|
raise ArgumentError, "nil cannot be some" if value.nil?
|
@@ -124,11 +112,11 @@ module Dry
|
|
124
112
|
if next_value.nil?
|
125
113
|
if self.class.warn_on_implicit_nil_coercion
|
126
114
|
Core::Deprecations.warn(
|
127
|
-
"Block passed to Some#fmap returned `nil` and was chained to None. "\
|
128
|
-
"This is literally an unlawful behavior and it will not be supported in "\
|
129
|
-
"dry-monads 2. \nPlease, replace `.fmap` with `.maybe` in places where you "\
|
130
|
-
"expect `nil` as block result.\n"\
|
131
|
-
"You can opt out of these warnings with\n"\
|
115
|
+
"Block passed to Some#fmap returned `nil` and was chained to None. " \
|
116
|
+
"This is literally an unlawful behavior and it will not be supported in " \
|
117
|
+
"dry-monads 2. \nPlease, replace `.fmap` with `.maybe` in places where you " \
|
118
|
+
"expect `nil` as block result.\n" \
|
119
|
+
"You can opt out of these warnings with\n" \
|
132
120
|
"Dry::Monads::Maybe.warn_on_implicit_nil_coercion false",
|
133
121
|
uplevel: 0,
|
134
122
|
tag: :"dry-monads"
|
@@ -151,9 +139,7 @@ module Dry
|
|
151
139
|
# @param args [Array<Object>] arguments will be transparently passed through to #bind
|
152
140
|
# @return [Maybe::Some, Maybe::None] Wrapped result, i.e. nil will be mapped to None,
|
153
141
|
# other values will be wrapped with Some
|
154
|
-
def maybe(...)
|
155
|
-
Maybe.coerce(bind(...))
|
156
|
-
end
|
142
|
+
def maybe(...) = Maybe.coerce(bind(...))
|
157
143
|
|
158
144
|
# Accepts a block and runs it against the wrapped value.
|
159
145
|
# If the block returns a trurhy value the result is self,
|
@@ -246,26 +232,19 @@ module Dry
|
|
246
232
|
# @param args [Array<Object>] arguments will be passed to the underlying `#or` call
|
247
233
|
# @return [Maybe::Some, Maybe::None] Lifted `#or` result, i.e. nil will be mapped to None,
|
248
234
|
# other values will be wrapped with Some
|
249
|
-
def or_fmap(...)
|
250
|
-
Maybe.coerce(self.or(...))
|
251
|
-
end
|
235
|
+
def or_fmap(...) = Maybe.coerce(self.or(...))
|
252
236
|
|
253
237
|
# @return [String]
|
254
|
-
def to_s
|
255
|
-
"None"
|
256
|
-
end
|
238
|
+
def to_s = "None"
|
257
239
|
alias_method :inspect, :to_s
|
258
240
|
|
259
241
|
# @api private
|
260
|
-
def eql?(other)
|
261
|
-
|
262
|
-
end
|
242
|
+
def eql?(other) = other.is_a?(None)
|
243
|
+
|
263
244
|
alias_method :==, :eql?
|
264
245
|
|
265
246
|
# @private
|
266
|
-
def hash
|
267
|
-
None.instance.object_id
|
268
|
-
end
|
247
|
+
def hash = None.instance.object_id
|
269
248
|
|
270
249
|
# Pattern matching
|
271
250
|
#
|
@@ -277,16 +256,12 @@ module Dry
|
|
277
256
|
# end
|
278
257
|
#
|
279
258
|
# @api private
|
280
|
-
def deconstruct
|
281
|
-
EMPTY_ARRAY
|
282
|
-
end
|
259
|
+
def deconstruct = EMPTY_ARRAY
|
283
260
|
|
284
261
|
# @see Maybe::Some#filter
|
285
262
|
#
|
286
263
|
# @return [Maybe::None]
|
287
|
-
def filter(_ = Undefined)
|
288
|
-
self
|
289
|
-
end
|
264
|
+
def filter(_ = Undefined) = self
|
290
265
|
end
|
291
266
|
|
292
267
|
# A module that can be included for easier access to Maybe monads.
|
@@ -302,9 +277,7 @@ module Dry
|
|
302
277
|
module Constructors
|
303
278
|
# @param value [Object] the value to be stored in the monad
|
304
279
|
# @return [Maybe::Some, Maybe::None]
|
305
|
-
def Maybe(value)
|
306
|
-
Maybe.coerce(value)
|
307
|
-
end
|
280
|
+
def Maybe(value) = Maybe.coerce(value)
|
308
281
|
|
309
282
|
# Some constructor
|
310
283
|
#
|
@@ -322,9 +295,7 @@ module Dry
|
|
322
295
|
end
|
323
296
|
|
324
297
|
# @return [Maybe::None]
|
325
|
-
def None
|
326
|
-
None.new(RightBiased::Left.trace_caller)
|
327
|
-
end
|
298
|
+
def None = None.new(RightBiased::Left.trace_caller)
|
328
299
|
end
|
329
300
|
|
330
301
|
include Constructors
|
@@ -393,9 +364,7 @@ module Dry
|
|
393
364
|
|
394
365
|
class Failure < Result
|
395
366
|
# @return [Maybe::None]
|
396
|
-
def to_maybe
|
397
|
-
Maybe::None.new(trace)
|
398
|
-
end
|
367
|
+
def to_maybe = Maybe::None.new(trace)
|
399
368
|
end
|
400
369
|
end
|
401
370
|
|
@@ -415,16 +384,12 @@ module Dry
|
|
415
384
|
class Try
|
416
385
|
class Value < Try
|
417
386
|
# @return [Maybe]
|
418
|
-
def to_maybe
|
419
|
-
Dry::Monads::Maybe(@value)
|
420
|
-
end
|
387
|
+
def to_maybe = ::Dry::Monads::Maybe(@value)
|
421
388
|
end
|
422
389
|
|
423
390
|
class Error < Try
|
424
391
|
# @return [Maybe::None]
|
425
|
-
def to_maybe
|
426
|
-
Maybe::None.new(RightBiased::Left.trace_caller)
|
427
|
-
end
|
392
|
+
def to_maybe = Maybe::None.new(RightBiased::Left.trace_caller)
|
428
393
|
end
|
429
394
|
end
|
430
395
|
|
@@ -433,18 +398,14 @@ module Dry
|
|
433
398
|
# Converts to Maybe::Some
|
434
399
|
#
|
435
400
|
# @return [Maybe::Some]
|
436
|
-
def to_maybe
|
437
|
-
Maybe.pure(value!)
|
438
|
-
end
|
401
|
+
def to_maybe = Maybe.pure(value!)
|
439
402
|
end
|
440
403
|
|
441
404
|
class Invalid < Validated
|
442
405
|
# Converts to Maybe::None
|
443
406
|
#
|
444
407
|
# @return [Maybe::None]
|
445
|
-
def to_maybe
|
446
|
-
Maybe::None.new(RightBiased::Left.trace_caller)
|
447
|
-
end
|
408
|
+
def to_maybe = Maybe::None.new(RightBiased::Left.trace_caller)
|
448
409
|
end
|
449
410
|
end
|
450
411
|
|
data/lib/dry/monads/registry.rb
CHANGED
@@ -43,9 +43,7 @@ module Dry
|
|
43
43
|
end
|
44
44
|
|
45
45
|
# @private
|
46
|
-
def known_monads
|
47
|
-
@constants.keys
|
48
|
-
end
|
46
|
+
def known_monads = @constants.keys
|
49
47
|
|
50
48
|
# @private
|
51
49
|
def load_monad(name)
|
@@ -59,15 +57,13 @@ module Dry
|
|
59
57
|
|
60
58
|
# @private
|
61
59
|
def constructors
|
62
|
-
@constructors ||= registry.values.filter_map
|
60
|
+
@constructors ||= registry.values.filter_map do |m|
|
63
61
|
m::Constructors if m.const_defined?(:Constructors)
|
64
|
-
|
62
|
+
end
|
65
63
|
end
|
66
64
|
|
67
65
|
# @private
|
68
|
-
def all_loaded?
|
69
|
-
registry.size.eql?(@constants.size)
|
70
|
-
end
|
66
|
+
def all_loaded? = registry.size.eql?(@constants.size)
|
71
67
|
end
|
72
68
|
end
|
73
69
|
end
|
@@ -8,11 +8,9 @@ module Dry
|
|
8
8
|
# @see Monads#Result
|
9
9
|
# @private
|
10
10
|
class Fixed < ::Module
|
11
|
-
def self.[](error, **options)
|
12
|
-
new(error, **options)
|
13
|
-
end
|
11
|
+
def self.[](error, **options) = new(error, **options)
|
14
12
|
|
15
|
-
def initialize(error, **
|
13
|
+
def initialize(error, **)
|
16
14
|
super()
|
17
15
|
|
18
16
|
@mod = ::Module.new do
|