dry-monads 1.3.5 → 1.5.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 +152 -80
- data/LICENSE +1 -1
- data/README.md +5 -4
- data/dry-monads.gemspec +31 -30
- data/lib/dry/monads/all.rb +2 -3
- data/lib/dry/monads/constants.rb +0 -2
- data/lib/dry/monads/curry.rb +2 -2
- data/lib/dry/monads/do/all.rb +35 -18
- data/lib/dry/monads/do.rb +48 -20
- data/lib/dry/monads/errors.rb +8 -5
- data/lib/dry/monads/lazy.rb +13 -5
- data/lib/dry/monads/list.rb +27 -37
- data/lib/dry/monads/maybe.rb +85 -26
- data/lib/dry/monads/registry.rb +20 -20
- data/lib/dry/monads/result/fixed.rb +31 -24
- data/lib/dry/monads/result.rb +37 -19
- data/lib/dry/monads/right_biased.rb +38 -31
- data/lib/dry/monads/task.rb +25 -28
- data/lib/dry/monads/transformer.rb +2 -1
- data/lib/dry/monads/traverse.rb +5 -1
- data/lib/dry/monads/try.rb +45 -18
- data/lib/dry/monads/unit.rb +9 -3
- data/lib/dry/monads/validated.rb +18 -18
- data/lib/dry/monads/version.rb +1 -1
- data/lib/dry/monads.rb +25 -4
- data/lib/dry-monads.rb +1 -1
- data/lib/json/add/dry/monads/maybe.rb +5 -5
- metadata +22 -54
- 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/lib/dry/monads/either.rb +0 -66
- data/log/.gitkeep +0 -0
- data/project.yml +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47e4a297e9fb56edfa596174c66abab2bee2587decfe47b474834ecbc2f13e41
|
4
|
+
data.tar.gz: 940384a98434a30026145d7caf12983440ac01fa63978885f4d72b4aafa1d76f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9076f344d5e8565b5acc9a3190d652a5f7f4217c04a0be8d4af7009c15779d84be0674f56a50a4bb473a679f608bf989df954d2c0408e67c7f3a1b4aa0bba86d
|
7
|
+
data.tar.gz: 99db2900d6fdd0af69d2e8b49303a3df85028fdf300b6998396e7bc6c6e60d1ca49bc684893fec4a5790e056d3af028e59f00251f960860eb65ce891291efa50
|
data/CHANGELOG.md
CHANGED
@@ -1,34 +1,103 @@
|
|
1
|
-
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.5.0 2022-10-16
|
4
|
+
|
5
|
+
|
6
|
+
### Changed
|
7
|
+
|
8
|
+
- Use zeitwerk for auto-loading dry-monads classes (@flash-gordon)
|
9
|
+
- `Task#then` is deprecated in favor of `Task#bind` (@flash-gordon)
|
10
|
+
- Minimal Ruby version is now 2.7 (@flash-gordon)
|
11
|
+
- Either (old name of Result) was removed (@flash-gordon)
|
12
|
+
|
13
|
+
[Compare v1.4.0...v1.5.0](https://github.com/dry-rb/dry-monads/compare/v1.4.0...v1.5.0)
|
14
|
+
|
15
|
+
## 1.4.0 2021-07-20
|
16
|
+
|
17
|
+
|
18
|
+
### Added
|
19
|
+
|
20
|
+
- `Unit` destructures to an empty array (flash-gordon)
|
21
|
+
- When `.value!` called on a `Failure` value the error references to the value (rewritten + flash-gordon)
|
22
|
+
```ruby
|
23
|
+
begin
|
24
|
+
Failure("oops").value!
|
25
|
+
rescue => error
|
26
|
+
error.receiver # => Failure("oops")
|
27
|
+
end
|
28
|
+
```
|
29
|
+
- `Result#alt_map` for mapping failure values (flash-gordon)
|
30
|
+
```ruby
|
31
|
+
Failure("oops").alt_map(&:upcase) # => Failure("OOPS")
|
32
|
+
```
|
33
|
+
- `Try#recover` recovers from errors (flash-gordon)
|
34
|
+
```ruby
|
35
|
+
error = Try { Hash.new.fetch(:missing) }
|
36
|
+
error.recover(KeyError) { 'default' } # => Try::Value("default")
|
37
|
+
```
|
38
|
+
- `Maybe#filter` runs a predicate against the wrapped value. Returns `None` if the result is false (flash-gordon)
|
39
|
+
```ruby
|
40
|
+
Some(3).filter(&:odd?) # => Some(3)
|
41
|
+
Some(3).filter(&:even?) # => None
|
42
|
+
# no block given
|
43
|
+
Some(3 == 5).filter # => None
|
44
|
+
```
|
45
|
+
- `RightBiased#|` is an alias for `#or` (flash-gordon)
|
46
|
+
```ruby
|
47
|
+
None() | Some(6) | Some(7) # => Some(6)
|
48
|
+
Failure() | Success("one") | Success("two") # => Success("one")
|
49
|
+
```
|
50
|
+
|
51
|
+
### Fixed
|
52
|
+
|
53
|
+
- Do notation preserves method visibility (anicholson + flash-gordon)
|
54
|
+
|
55
|
+
### Changed
|
56
|
+
|
57
|
+
- Coercing `nil` values to `None` with `Some#fmap` is officially deprecated. (flash-gordon)
|
58
|
+
Switch to `Some#maybe` when you expect `nil`.
|
59
|
+
This behavior will be dropped in 2.0 but you can opt out of warnings for the time being
|
60
|
+
```ruby
|
61
|
+
Dry::Monads::Maybe.warn_on_implicit_nil_coercion false
|
62
|
+
```
|
63
|
+
- Minimal Ruby version is 2.6
|
64
|
+
|
65
|
+
[Compare v1.3.5...v1.4.0](https://github.com/dry-rb/dry-monads/compare/v1.3.5...v1.4.0)
|
66
|
+
|
67
|
+
## 1.3.5 2020-01-06
|
68
|
+
|
69
|
+
|
70
|
+
### Added
|
4
71
|
|
5
72
|
- Smarter keys deconstruction in pattern matching (flash-gordon)
|
6
73
|
|
74
|
+
|
7
75
|
[Compare v1.3.4...v1.3.5](https://github.com/dry-rb/dry-monads/compare/v1.3.4...v1.3.5)
|
8
76
|
|
9
|
-
|
77
|
+
## 1.3.4 2019-12-28
|
10
78
|
|
11
|
-
|
79
|
+
|
80
|
+
### Fixed
|
12
81
|
|
13
82
|
- One more delegation warning happenning in do notation (flash-gordon)
|
14
83
|
|
84
|
+
|
15
85
|
[Compare v1.3.3...v1.3.4](https://github.com/dry-rb/dry-monads/compare/v1.3.3...v1.3.4)
|
16
86
|
|
17
|
-
|
87
|
+
## 1.3.3 2019-12-11
|
88
|
+
|
18
89
|
|
19
|
-
|
90
|
+
### Fixed
|
20
91
|
|
21
92
|
- Incompatibility with Rails. Internal (!) halt exceptions now use mutable backtraces because spring [mutates](https://github.com/rails/spring/blob/ee687859008e947bc905b95121e306e2948d31c9/lib/spring/application.rb#L295-L311) (!) them. For the record, this a bug in Rails (johnmaxwell)
|
22
93
|
|
23
|
-
[Compare v1.3.2...v1.3.3](https://github.com/dry-rb/dry-monads/compare/v1.3.2...v1.3.3)
|
24
94
|
|
25
|
-
|
95
|
+
[Compare v1.3.2...v1.3.3](https://github.com/dry-rb/dry-monads/compare/v1.3.2...v1.3.3)
|
26
96
|
|
27
|
-
##
|
97
|
+
## 1.3.2 2019-11-30
|
28
98
|
|
29
|
-
- Warnings about keywords from Ruby 2.7 (flash-gordon)
|
30
99
|
|
31
|
-
|
100
|
+
### Added
|
32
101
|
|
33
102
|
- Pattern matching syntax was improved by implementing `#deconstruct_keys`. Now curly braces aren't necessary when the wrapped value is a Hash (flash-gordon)
|
34
103
|
```ruby
|
@@ -36,28 +105,30 @@
|
|
36
105
|
in Success(code: 200...300) then :ok
|
37
106
|
end
|
38
107
|
```
|
108
|
+
- ## Internal
|
109
|
+
- Performance of do notation was improved for failing cases (1.2x to 1.3x on synthetic benchmarks) (flash-gordon)
|
39
110
|
|
40
|
-
|
111
|
+
### Fixed
|
112
|
+
|
113
|
+
- Warnings about keywords from Ruby 2.7 (flash-gordon)
|
41
114
|
|
42
|
-
- Performance of do notation was improved for failing cases (1.2x to 1.3x on synthetic benchmarks) (flash-gordon)
|
43
115
|
|
44
116
|
[Compare v1.3.1...v1.3.2](https://github.com/dry-rb/dry-monads/compare/v1.3.1...v1.3.2)
|
45
117
|
|
46
|
-
|
118
|
+
## 1.3.1 2019-09-07
|
119
|
+
|
47
120
|
|
48
|
-
|
121
|
+
### Fixed
|
49
122
|
|
50
123
|
- Added missing `None#maybe` :sweat_smile: (flash-gordon)
|
51
124
|
|
52
|
-
[Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-monads/compare/v1.3.0...v1.3.1)
|
53
125
|
|
54
|
-
|
126
|
+
[Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-monads/compare/v1.3.0...v1.3.1)
|
55
127
|
|
56
|
-
##
|
128
|
+
## 1.3.0 2019-08-03
|
57
129
|
|
58
|
-
- Support for Ruby 2.3 was dropped.
|
59
130
|
|
60
|
-
|
131
|
+
### Added
|
61
132
|
|
62
133
|
- `Result#either` (waiting-for-dev)
|
63
134
|
```ruby
|
@@ -101,7 +172,6 @@
|
|
101
172
|
Dry::Monads.Success(a + b)
|
102
173
|
end
|
103
174
|
```
|
104
|
-
|
105
175
|
- `{Some,Success,Failure}#[]` shortcuts for building arrays wrapped within monadic value (flash-gordon)
|
106
176
|
```ruby
|
107
177
|
Success[1, 2] # => Success([1, 2])
|
@@ -117,7 +187,6 @@
|
|
117
187
|
end
|
118
188
|
end # => List[1, 2, 3, 4, 5]
|
119
189
|
```
|
120
|
-
|
121
190
|
- Experimental support for pattern matching! :tada: (flash-gordon)
|
122
191
|
|
123
192
|
```ruby
|
@@ -140,15 +209,13 @@
|
|
140
209
|
|
141
210
|
Keep in mind this feature is experimental and can be changed by 2.7 release. But it rocks already!
|
142
211
|
|
143
|
-
[Compare v1.2.0...v1.3.0](https://github.com/dry-rb/dry-monads/compare/v1.2.0...v1.3.0)
|
144
212
|
|
145
|
-
|
213
|
+
[Compare v1.2.0...v1.3.0](https://github.com/dry-rb/dry-monads/compare/v1.2.0...v1.3.0)
|
146
214
|
|
147
|
-
##
|
215
|
+
## 1.2.0 2019-01-12
|
148
216
|
|
149
|
-
- Support for Ruby 2.2 was dropped. Ruby 2.2 reached its EOL on March 31, 2018.
|
150
217
|
|
151
|
-
|
218
|
+
### Added
|
152
219
|
|
153
220
|
- Most of constructors now have `call` alias so you can compose them with Procs nicely if you've switched to Ruby 2.6 (flash-gordon)
|
154
221
|
```ruby
|
@@ -177,7 +244,6 @@
|
|
177
244
|
List[Some(5), None(), Some(3)].collect.map { |x| x * 2 }
|
178
245
|
# => [10, 6]
|
179
246
|
```
|
180
|
-
|
181
247
|
- Right-biased monads got `#flatten` and `#and` (falsh-gordon)
|
182
248
|
|
183
249
|
`#flatten` removes one level of monadic structure, it's useful when you're dealing with things like `Maybe` of `Maybe` of something:
|
@@ -209,7 +275,6 @@
|
|
209
275
|
Some(5).and(None()) # => None()
|
210
276
|
None().and(Some(5)) # => None()
|
211
277
|
```
|
212
|
-
|
213
278
|
- Concise imports with `Dry::Monads.[]`. You're no longer required to require all desired monads and include them one-by-one, the `[]` method handles it for you (flash-gordon)
|
214
279
|
|
215
280
|
```ruby
|
@@ -234,18 +299,15 @@
|
|
234
299
|
end
|
235
300
|
end
|
236
301
|
```
|
237
|
-
|
238
302
|
- `Task.failed` is a counterpart of `Task.pure`, accepts an exception and returns a failed task immediately (flash-gordon)
|
239
303
|
|
240
|
-
[Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-monads/compare/v1.1.0...v1.2.0)
|
241
304
|
|
242
|
-
|
305
|
+
[Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-monads/compare/v1.1.0...v1.2.0)
|
243
306
|
|
244
|
-
##
|
307
|
+
## 1.1.0 2018-10-16
|
245
308
|
|
246
|
-
- Do notation was made to work nicely with inheritance. This shouldn't break any existing code but if it does please report (flash-gordon)
|
247
309
|
|
248
|
-
|
310
|
+
### Added
|
249
311
|
|
250
312
|
- `Success()`, `Failure()`, and `Some()` now have `Unit` as a default argument:
|
251
313
|
|
@@ -261,26 +323,34 @@
|
|
261
323
|
end
|
262
324
|
```
|
263
325
|
|
264
|
-
|
326
|
+
### Fixed
|
265
327
|
|
266
|
-
|
328
|
+
- Do notation was made to work nicely with inheritance. This shouldn't break any existing code but if it does please report (flash-gordon)
|
267
329
|
|
268
|
-
## Fixed
|
269
330
|
|
270
|
-
|
331
|
+
[Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-monads/compare/v1.0.1...v1.1.0)
|
271
332
|
|
272
|
-
##
|
333
|
+
## 1.0.1 2018-08-11
|
334
|
+
|
335
|
+
|
336
|
+
### Added
|
273
337
|
|
274
338
|
- `to_proc` was added to value constructors (flash-gordon)
|
275
339
|
```ruby
|
276
340
|
[1, 2, 3].map(&Some) # => [Some(1), Some(2), Some(3)]
|
277
341
|
```
|
278
342
|
|
343
|
+
### Fixed
|
344
|
+
|
345
|
+
- Fixed behavior of `List<Validated>#traverse` in presence of `Valid` values (flash-gordon + SunnyMagadan)
|
346
|
+
|
347
|
+
|
279
348
|
[Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-monads/compare/v1.0.0...v1.0.1)
|
280
349
|
|
281
|
-
|
350
|
+
## 1.0.0 2018-06-26
|
282
351
|
|
283
|
-
|
352
|
+
|
353
|
+
### Added
|
284
354
|
|
285
355
|
- `do`-like notation (the idea comes from Haskell of course). This is the biggest and most important addition to the release which greatly increases the ergonomics of using monads in Ruby. Basically, almost everything it does is passing a block to a given method. You call `yield` on monads to extract the values. If any operation fails i.e. no value can be extracted, the whole computation is halted and the failing step becomes a result. With `Do` you don't need to chain monadic values with `fmap/bind` and block, everything can be done on a single level of indentation. Here is a more or less real-life example:
|
286
356
|
|
@@ -332,7 +402,6 @@
|
|
332
402
|
```
|
333
403
|
|
334
404
|
In the code above any `yield` can potentially fail and return the failure reason as a result. In other words, `yield None` acts as `return None`. Internally, `Do` uses exceptions, not `return`, this is somewhat slower but allows to detect failed operations in DB-transactions and roll back the changes which far more useful than an unjustifiable speed boost (flash-gordon)
|
335
|
-
|
336
405
|
- The `Task` monad based on `Promise` from the [`concurrent-ruby` gem](https://github.com/ruby-concurrency/concurrent-ruby/). `Task` represents an asynchronous computation which _can be_ (doesn't have to!) run on a separated thread. `Promise` already offers a good API and implemented in a safe manner so `dry-monads` just adds a monad-compatible interface for it. Out of the box, `concurrent-ruby` has three types of executors for running blocks: `:io`, `:fast`, `:immediate`, check out [the docs](http://ruby-concurrency.github.io/concurrent-ruby/root/Concurrent.html#executor-class_method) for details. You can provide your own executor if needed (flash-gordon)
|
337
406
|
|
338
407
|
```ruby
|
@@ -358,9 +427,7 @@
|
|
358
427
|
Success(create(e, n))
|
359
428
|
end
|
360
429
|
```
|
361
|
-
|
362
430
|
- `Lazy` is a copy of `Task` that isn't run until you ask for the value _for the first time_. It is guaranteed the evaluation is run at most once as opposed to lazy assignment `||=` which isn't synchronized. `Lazy` is run on the same thread asking for the value (flash-gordon)
|
363
|
-
|
364
431
|
- Automatic type inference with `.typed` for lists was deprecated. Instead, typed list builders were added
|
365
432
|
|
366
433
|
```ruby
|
@@ -369,7 +436,6 @@
|
|
369
436
|
```
|
370
437
|
|
371
438
|
The code above runs two tasks in parallel and automatically combines their results with `traverse` (flash-gordon)
|
372
|
-
|
373
439
|
- `Try` got a new call syntax supported in Ruby 2.5+
|
374
440
|
|
375
441
|
```ruby
|
@@ -377,7 +443,6 @@
|
|
377
443
|
```
|
378
444
|
|
379
445
|
Prior to 2.5, it wasn't possible to pass a block to `[]`.
|
380
|
-
|
381
446
|
- The `Validated` “monad” that represents a result of a validation. Suppose, you want to collect all the errors and return them at once. You can't have it with `Result` because when you `traverse` a `List` of `Result`s it returns the first value and this is the correct behavior from the theoretical point of view. `Validated`, in fact, doesn't have a monad instance but provides a useful variant of applicative which concatenates the errors.
|
382
447
|
|
383
448
|
```ruby
|
@@ -401,13 +466,11 @@
|
|
401
466
|
```
|
402
467
|
|
403
468
|
In the example above an array of `Validated` values is implicitly coerced to `List::Validated`. It's supported because it's useful but don't forget it's all about types so don't mix different types of monads in a single array, the consequences are unclear. You always can be explicit with `List::Validated[validate_name(...), ...]`, choose what you like (flash-gordon).
|
404
|
-
|
405
469
|
- `Failure`, `None`, and `Invalid` values now store the line where they were created. One of the biggest downsides of dealing with monadic code is lack of backtraces. If you have a long list of computations and one of them fails how do you know where did it actually happen? Say, you've got `None` and this tells you nothing about _what variable_ was assigned to `None`. It makes sense to use `Result` instead of `Maybe` and use distinct errors everywhere but it doesn't always look good and forces you to think more. TLDR; call `.trace` to get the line where a fail-case was constructed
|
406
470
|
|
407
471
|
```ruby
|
408
472
|
Failure(:invalid_name).trace # => app/operations/create_user.rb:43
|
409
473
|
```
|
410
|
-
|
411
474
|
- `Dry::Monads::Unit` which can be used as a replacement for `Success(nil)` and in similar situations when you have side effects yet doesn't return anything meaningful as a result. There's also the `.discard` method for mapping any successful result (i.e. `Success(?)`, `Some(?)`, `Value(?)`, etc) to `Unit`.
|
412
475
|
|
413
476
|
```ruby
|
@@ -417,26 +480,19 @@
|
|
417
480
|
# ... wait for the task to finish ...
|
418
481
|
# => Task(valut=Unit)
|
419
482
|
```
|
420
|
-
|
421
|
-
## Deprecations
|
422
|
-
|
483
|
+
- ## Deprecations
|
423
484
|
- `Either`, the former name of `Result`, is now deprecated
|
424
|
-
|
425
|
-
## BREAKING CHANGES
|
426
|
-
|
485
|
+
- ## BREAKING CHANGES
|
427
486
|
- `Either#value` and `Maybe#value` were both droped, use `value_or` or `value!` when you :100: sure it's safe
|
428
487
|
- `require 'dry/monads'` doesn't load all monads anymore, use `require 'dry/monads/all'` instead or cherry pick them with `require 'dry/monads/maybe'` etc (timriley)
|
429
488
|
|
430
|
-
[Compare v0.4.0...v1.0.0](https://github.com/dry-rb/dry-monads/compare/v0.4.0...v1.0.0)
|
431
489
|
|
432
|
-
|
490
|
+
[Compare v0.4.0...v1.0.0](https://github.com/dry-rb/dry-monads/compare/v0.4.0...v1.0.0)
|
433
491
|
|
434
|
-
##
|
492
|
+
## 0.4.0 2017-11-11
|
435
493
|
|
436
|
-
- The `Either` monad was renamed to `Result` which sounds less nerdy but better reflects the purpose of the type. `Either::Right` became `Result::Success` and `Either::Left` became `Result::Failure`. This change is backward-compatible overall but you will see the new names when using old `Left` and `Right` methods (citizen428)
|
437
|
-
- Consequently, `Try::Success` and `Try::Failure` were renamed to `Try::Value` and `Try::Error` (flash-gordon)
|
438
494
|
|
439
|
-
|
495
|
+
### Added
|
440
496
|
|
441
497
|
- `Try#or`, works as `Result#or` (flash-gordon)
|
442
498
|
- `Maybe#success?` and `Maybe#failure?` (aliases for `#some?` and `#none?`) (flash-gordon)
|
@@ -451,24 +507,30 @@
|
|
451
507
|
else raise TypeError
|
452
508
|
end
|
453
509
|
```
|
510
|
+
- ## Deprecated
|
511
|
+
- Direct accessing `value` on right-biased monads has been deprecated, use the `value!` method instead. `value!` will raise an exception if it is called on a Failure/None/Error instance (flash-gordon)
|
454
512
|
|
455
|
-
|
513
|
+
### Changed
|
456
514
|
|
457
|
-
-
|
515
|
+
- The `Either` monad was renamed to `Result` which sounds less nerdy but better reflects the purpose of the type. `Either::Right` became `Result::Success` and `Either::Left` became `Result::Failure`. This change is backward-compatible overall but you will see the new names when using old `Left` and `Right` methods (citizen428)
|
516
|
+
- Consequently, `Try::Success` and `Try::Failure` were renamed to `Try::Value` and `Try::Error` (flash-gordon)
|
458
517
|
|
459
518
|
[Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-monads/compare/v0.3.1...v0.4.0)
|
460
519
|
|
461
|
-
|
520
|
+
## 0.3.1 2017-03-18
|
521
|
+
|
462
522
|
|
463
|
-
|
523
|
+
### Fixed
|
464
524
|
|
465
525
|
- Fixed unexpected coercing to `Hash` on `.bind` call (flash-gordon)
|
466
526
|
|
527
|
+
|
467
528
|
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-monads/compare/v0.3.0...v0.3.1)
|
468
529
|
|
469
|
-
|
530
|
+
## 0.3.0 2017-03-16
|
531
|
+
|
470
532
|
|
471
|
-
|
533
|
+
### Added
|
472
534
|
|
473
535
|
- Added `Either#either` that accepts two callbacks, runs the first if it is `Right` and the second otherwise (nkondratyev)
|
474
536
|
- Added `#fmap2` and `#fmap3` for mapping over nested structures like `List Either` and `Either Some` (flash-gordon)
|
@@ -478,59 +540,69 @@
|
|
478
540
|
- Added `List#traverse` that "flips" the list with an embedded monad (flash-gordon + damncabbage)
|
479
541
|
- Added `#tee` for all right-biased monads (flash-gordon)
|
480
542
|
|
543
|
+
|
481
544
|
[Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-monads/compare/v0.2.1...v0.3.0)
|
482
545
|
|
483
|
-
|
546
|
+
## 0.2.1 2016-11-13
|
484
547
|
|
485
|
-
|
548
|
+
|
549
|
+
### Added
|
486
550
|
|
487
551
|
- Added `Either#tee` that is similar to `Object#tap` but executes the block only for `Right` instances (saverio-kantox)
|
488
552
|
|
489
|
-
|
553
|
+
### Fixed
|
490
554
|
|
491
555
|
- `Right(nil).to_maybe` now returns `None` with a warning instead of failing (orisaka)
|
492
556
|
- `Some#value_or` doesn't require an argument because `None#value_or` doesn't require it either if a block was passed (flash-gordon)
|
493
557
|
|
558
|
+
|
494
559
|
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-monads/compare/v0.2.0...v0.2.1)
|
495
560
|
|
496
|
-
|
561
|
+
## 0.2.0 2016-09-18
|
562
|
+
|
497
563
|
|
498
|
-
|
564
|
+
### Added
|
499
565
|
|
500
566
|
- Added `Maybe#to_json` as an opt-in extension for serialization to JSON (rocknruby)
|
501
567
|
- Added `Maybe#value_or` which returns you the underlying value with a fallback in a single method call (dsounded)
|
502
568
|
|
569
|
+
|
503
570
|
[Compare v0.1.1...v0.2.0](https://github.com/dry-rb/dry-monads/compare/v0.1.1...v0.2.0)
|
504
571
|
|
505
|
-
|
572
|
+
## 0.1.1 2016-08-25
|
573
|
+
|
506
574
|
|
507
|
-
|
575
|
+
### Fixed
|
508
576
|
|
509
577
|
- Added explicit requires of `dry-equalizer`. This allows to safely load only specific monads (artofhuman)
|
510
578
|
|
579
|
+
|
511
580
|
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-monads/compare/v0.1.0...v0.1.1)
|
512
581
|
|
513
|
-
|
582
|
+
## 0.1.0 2016-08-23
|
514
583
|
|
515
|
-
|
584
|
+
|
585
|
+
### Added
|
516
586
|
|
517
587
|
- Support for passing extra arguments to the block in `.bind` and `.fmap` (flash-gordon)
|
518
588
|
|
519
|
-
|
589
|
+
### Changed
|
520
590
|
|
521
591
|
- Dropped MRI 2.0 support (flash-gordon)
|
522
592
|
|
523
593
|
[Compare v0.0.2...v0.1.0](https://github.com/dry-rb/dry-monads/compare/v0.0.2...v0.1.0)
|
524
594
|
|
525
|
-
|
595
|
+
## 0.0.2 2016-06-29
|
596
|
+
|
526
597
|
|
527
|
-
|
598
|
+
### Added
|
528
599
|
|
529
600
|
- Added `Either#to_either` so that you can rely on duck-typing when you work with different types of monads (timriley)
|
530
601
|
- Added `Maybe#to_maybe` for consistency with `#to_either` (flash-gordon)
|
531
602
|
|
603
|
+
|
532
604
|
[Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-monads/compare/v0.0.1...v0.0.2)
|
533
605
|
|
534
|
-
|
606
|
+
## 0.0.1 2016-05-02
|
535
607
|
|
536
608
|
Initial release containing `Either`, `Maybe`, and `Try` monads.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
1
2
|
[gem]: https://rubygems.org/gems/dry-monads
|
2
3
|
[actions]: https://github.com/dry-rb/dry-monads/actions
|
3
4
|
[codacy]: https://www.codacy.com/gh/dry-rb/dry-monads
|
@@ -10,19 +11,19 @@
|
|
10
11
|
[![CI Status](https://github.com/dry-rb/dry-monads/workflows/ci/badge.svg)][actions]
|
11
12
|
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/f2eed41bf7f04b38b0a7691c2cf6e73c)][codacy]
|
12
13
|
[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f2eed41bf7f04b38b0a7691c2cf6e73c)][codacy]
|
13
|
-
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-monads.svg?branch=
|
14
|
+
[![Inline docs](http://inch-ci.org/github/dry-rb/dry-monads.svg?branch=main)][inchpages]
|
14
15
|
|
15
16
|
## Links
|
16
17
|
|
17
|
-
* [User documentation](
|
18
|
+
* [User documentation](https://dry-rb.org/gems/dry-monads)
|
18
19
|
* [API documentation](http://rubydoc.info/gems/dry-monads)
|
19
20
|
|
20
21
|
## Supported Ruby versions
|
21
22
|
|
22
23
|
This library officially supports the following Ruby versions:
|
23
24
|
|
24
|
-
* MRI
|
25
|
-
* jruby
|
25
|
+
* MRI `>= 2.7.0`
|
26
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
26
27
|
|
27
28
|
## License
|
28
29
|
|
data/dry-monads.gemspec
CHANGED
@@ -1,39 +1,40 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
4
|
+
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
4
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require
|
7
|
+
require "dry/monads/version"
|
6
8
|
|
7
9
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name =
|
10
|
+
spec.name = "dry-monads"
|
11
|
+
spec.authors = ["Nikita Shilnikov"]
|
12
|
+
spec.email = ["fg@flashgordon.ru"]
|
13
|
+
spec.license = "MIT"
|
9
14
|
spec.version = Dry::Monads::VERSION.dup
|
10
|
-
spec.authors = ['Nikita Shilnikov']
|
11
|
-
spec.email = ['fg@flashgordon.ru']
|
12
|
-
spec.license = 'MIT'
|
13
15
|
|
14
|
-
spec.summary =
|
16
|
+
spec.summary = "Common monads for Ruby"
|
15
17
|
spec.description = spec.summary
|
16
|
-
spec.homepage =
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
spec.
|
28
|
-
|
29
|
-
|
30
|
-
spec.
|
31
|
-
spec.
|
32
|
-
spec.
|
33
|
-
|
34
|
-
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency 'rspec'
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-monads"
|
19
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-monads.gemspec", "lib/**/*"]
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = []
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
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
|
+
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
30
|
+
|
31
|
+
# to update dependencies edit project.yml
|
32
|
+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
33
|
+
spec.add_runtime_dependency "dry-core", "~> 0.9", ">= 0.9"
|
34
|
+
spec.add_runtime_dependency "zeitwerk", "~> 2.6"
|
35
|
+
|
36
|
+
spec.add_development_dependency "bundler"
|
37
|
+
spec.add_development_dependency "dry-types", ">= 0.1.2"
|
38
|
+
spec.add_development_dependency "rake"
|
39
|
+
spec.add_development_dependency "rspec"
|
39
40
|
end
|
data/lib/dry/monads/all.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require 'dry/monads/registry'
|
3
|
+
require "dry/monads"
|
5
4
|
|
6
5
|
module Dry
|
7
6
|
module Monads
|
8
|
-
known_monads.each {
|
7
|
+
known_monads.each { load_monad(_1) }
|
9
8
|
extend(*constructors)
|
10
9
|
end
|
11
10
|
end
|
data/lib/dry/monads/constants.rb
CHANGED
data/lib/dry/monads/curry.rb
CHANGED
@@ -7,8 +7,8 @@ module Dry
|
|
7
7
|
# @private
|
8
8
|
def self.call(value)
|
9
9
|
func = value.is_a?(Proc) ? value : value.method(:call)
|
10
|
-
seq_args = func.parameters.count { |type, _| type
|
11
|
-
seq_args += 1 if func.parameters.any? { |type, _| type
|
10
|
+
seq_args = func.parameters.count { |type, _| type.eql?(:req) || type.eql?(:opt) }
|
11
|
+
seq_args += 1 if func.parameters.any? { |type, _| type.eql?(:keyreq) }
|
12
12
|
|
13
13
|
if seq_args > 1
|
14
14
|
func.curry
|