dry-monads 1.3.0 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +10 -39
  3. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +10 -0
  4. data/.github/ISSUE_TEMPLATE/---bug-report.md +30 -0
  5. data/.github/ISSUE_TEMPLATE/---feature-request.md +18 -0
  6. data/.github/workflows/ci.yml +52 -0
  7. data/.github/workflows/docsite.yml +34 -0
  8. data/.github/workflows/sync_configs.yml +56 -0
  9. data/.rspec +1 -0
  10. data/.rubocop.yml +101 -0
  11. data/CHANGELOG.md +130 -62
  12. data/CODE_OF_CONDUCT.md +13 -0
  13. data/CONTRIBUTING.md +4 -4
  14. data/Gemfile +7 -8
  15. data/Gemfile.devtools +14 -0
  16. data/LICENSE +17 -17
  17. data/README.md +17 -38
  18. data/Rakefile +2 -0
  19. data/bin/.gitkeep +0 -0
  20. data/bin/console +1 -0
  21. data/docsite/source/case-equality.html.md +42 -0
  22. data/docsite/source/do-notation.html.md +207 -0
  23. data/docsite/source/getting-started.html.md +142 -0
  24. data/docsite/source/index.html.md +179 -0
  25. data/docsite/source/list.html.md +87 -0
  26. data/docsite/source/maybe.html.md +146 -0
  27. data/docsite/source/pattern-matching.html.md +68 -0
  28. data/docsite/source/result.html.md +190 -0
  29. data/docsite/source/task.html.md +126 -0
  30. data/docsite/source/tracing-failures.html.md +32 -0
  31. data/docsite/source/try.html.md +76 -0
  32. data/docsite/source/unit.html.md +36 -0
  33. data/docsite/source/validated.html.md +88 -0
  34. data/dry-monads.gemspec +7 -5
  35. data/lib/dry-monads.rb +2 -0
  36. data/lib/dry/monads.rb +3 -0
  37. data/lib/dry/monads/all.rb +2 -0
  38. data/lib/dry/monads/{undefined.rb → constants.rb} +3 -1
  39. data/lib/dry/monads/conversion_stubs.rb +2 -0
  40. data/lib/dry/monads/curry.rb +2 -0
  41. data/lib/dry/monads/do.rb +7 -2
  42. data/lib/dry/monads/do/all.rb +5 -2
  43. data/lib/dry/monads/do/mixin.rb +4 -3
  44. data/lib/dry/monads/either.rb +2 -0
  45. data/lib/dry/monads/errors.rb +4 -2
  46. data/lib/dry/monads/lazy.rb +4 -2
  47. data/lib/dry/monads/list.rb +10 -9
  48. data/lib/dry/monads/maybe.rb +9 -4
  49. data/lib/dry/monads/registry.rb +5 -2
  50. data/lib/dry/monads/result.rb +5 -4
  51. data/lib/dry/monads/result/fixed.rb +4 -2
  52. data/lib/dry/monads/right_biased.rb +55 -8
  53. data/lib/dry/monads/task.rb +6 -3
  54. data/lib/dry/monads/transformer.rb +2 -0
  55. data/lib/dry/monads/traverse.rb +2 -0
  56. data/lib/dry/monads/try.rb +6 -1
  57. data/lib/dry/monads/validated.rb +12 -9
  58. data/lib/dry/monads/version.rb +3 -1
  59. data/lib/json/add/dry/monads/maybe.rb +1 -0
  60. data/project.yml +2 -0
  61. metadata +45 -22
  62. data/.travis.yml +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b5983b622b49edc1008fc8717adf6f4150f011c55ca094879f6788cfed657f2
4
- data.tar.gz: 8e01a982d197dbc26e82df01c804dba93e8aa327aeb9cb248a07eeda7a7c636c
3
+ metadata.gz: 86fbad001116e7a69e01b2f7e8b0c5ee8101a95af73fd9f485880131df364749
4
+ data.tar.gz: 5d3a4bf072bfcfe22edb31512a4b29b5952c7aaa674af4b1ef546dc8ce39e302
5
5
  SHA512:
6
- metadata.gz: f81e00f7455a03b12996724fd35404d81dff4cbc934e1868a2329c26cbaae5cb7f5edcde6c9766f754844e8ce0b839d5ca10781e0c1c08702020e938956703b3
7
- data.tar.gz: 4ea9d2ffa5988996517ba096ef8985331a213fadbdb6d81b2597012a0d7ada3da3716422ba155accd0a9932bf5802a905a3b19162526c5f2a501f45e0b46537e
6
+ metadata.gz: aaa55a8f21b5e84d9b4029a59733a72c4bd21ccfd76430faa4eb39c821860e774e0a94e9fddbecd66a6e0c9c876d7178dc66a2364b85851ecbf56fb8b6ac5e86
7
+ data.tar.gz: 126cc641f1ba8ba33fd251e63d18668c1360eff70967f86705a333fcd01df95cc3909579a128e270629b4609179db435fdeb0de0d3a5fcdb2ef0693ccc3fcc49
@@ -1,41 +1,12 @@
1
- engines:
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ version: "2"
4
+
5
+ exclude_patterns:
6
+ - "benchmarks/"
7
+ - "examples/"
8
+ - "spec/"
9
+
10
+ plugins:
2
11
  rubocop:
3
12
  enabled: true
4
- checks:
5
- Rubocop/Style/Documentation:
6
- enabled: false
7
- Rubocop/Style/StringLiterals:
8
- enabled: false
9
- Rubocop/Style/MethodName:
10
- enabled: false
11
- Rubocop/Style/LambdaCall:
12
- enabled: false
13
- Rubocop/Style/StabbyLambdaParentheses:
14
- enabled: false
15
- Rubocop/Style/NestedParenthesizedCalls:
16
- enabled: false
17
- Rubocop/Style/MultilineBlockChain:
18
- enabled: false
19
- Rubocop/Style/GuardClause:
20
- enabled: false
21
- Rubocop/Metrics/LineLength:
22
- enabled: true
23
- max: 110
24
- Rubocop/Style/FileName:
25
- enabled: true
26
- exclude:
27
- - 'lib/dry-monads.rb'
28
- Rubocop/Lint/Debugger:
29
- enabled: true
30
- exclude:
31
- - 'bin/console'
32
- Rubocop/Lint/HandleExceptions:
33
- enabled: true
34
- exclude:
35
- - 'spec/spec_helper.rb'
36
- ratings:
37
- paths:
38
- - lib/**/*.rb
39
- exclude_paths:
40
- - spec/**/*
41
- - examples/**/*
@@ -0,0 +1,10 @@
1
+ ---
2
+ name: "⚠️ Please don't ask for support via issues"
3
+ about: See CONTRIBUTING.md for more information
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+
@@ -0,0 +1,30 @@
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: ...
@@ -0,0 +1,18 @@
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.
@@ -0,0 +1,52 @@
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
@@ -0,0 +1,34 @@
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
@@ -0,0 +1,56 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ name: sync_configs
4
+
5
+ on:
6
+ repository_dispatch:
7
+
8
+ jobs:
9
+ sync-configs:
10
+ runs-on: ubuntu-latest
11
+ if: github.event.action == 'sync_configs'
12
+ steps:
13
+ - uses: actions/checkout@v1
14
+ - name: Set up Ruby
15
+ uses: eregon/use-ruby-action@master
16
+ with:
17
+ ruby-version: 2.6
18
+ - name: Install latest bundler
19
+ run: |
20
+ gem install bundler
21
+ bundle config set without 'tools benchmarks docs'
22
+ - name: Install dependencies
23
+ run: bundle install --jobs 4 --retry 3 --without tools test benchmarks docs
24
+ - name: Symlink ossy
25
+ run: ln -sf "$(bundle info ossy --path)/bin/ossy" bin/ossy
26
+ - name: Clone devtools
27
+ run: git clone https://github.com/dry-rb/devtools.git tmp/devtools
28
+ - name: Compile file templates
29
+ env:
30
+ GITHUB_LOGIN: dry-bot
31
+ GITHUB_TOKEN: ${{ secrets.GH_PAT }}
32
+ run: |
33
+ if [ -f "project.yml" ]; then
34
+ for t in `ls tmp/devtools/templates`
35
+ do
36
+ bin/ossy t c tmp/devtools/templates/$t $(basename $t .erb) project.yml
37
+ done
38
+ fi
39
+ - name: Update configuration files from devtools
40
+ run: |
41
+ if [ -f ".github/workflows/custom_ci.yml" ]; then
42
+ rsync -arv --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
43
+ else
44
+ rsync -arv tmp/devtools/shared/ . ;
45
+ fi
46
+ - name: Commit changes
47
+ run: |
48
+ rm bin/ossy
49
+ git config --local user.email "dry-bot@dry-rb.org"
50
+ git config --local user.name "dry-bot"
51
+ git add -A
52
+ git commit -m "[devtools] sync configs" || echo "nothing changed"
53
+ - name: Push changes
54
+ uses: ad-m/github-push-action@master
55
+ with:
56
+ github_token: ${{ secrets.GH_PAT }}
data/.rspec CHANGED
@@ -1,3 +1,4 @@
1
1
  --color
2
2
  --require spec_helper
3
3
  --order random
4
+ --warnings
@@ -0,0 +1,101 @@
1
+ # this file is managed by dry-rb/devtools project
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+
6
+ Style/EachWithObject:
7
+ Enabled: false
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: single_quotes
12
+
13
+ Style/ParallelAssignment:
14
+ Enabled: false
15
+
16
+ Style/Alias:
17
+ Enabled: false
18
+
19
+ Style/LambdaCall:
20
+ Enabled: false
21
+
22
+ Style/StabbyLambdaParentheses:
23
+ Enabled: false
24
+
25
+ Style/FormatString:
26
+ Enabled: false
27
+
28
+ Style/Documentation:
29
+ Enabled: false
30
+
31
+ Layout/SpaceInLambdaLiteral:
32
+ Enabled: false
33
+
34
+ Layout/MultilineMethodCallIndentation:
35
+ Enabled: true
36
+ EnforcedStyle: indented
37
+
38
+ Metrics/LineLength:
39
+ Max: 100
40
+
41
+ Metrics/MethodLength:
42
+ Enabled: false
43
+
44
+ Metrics/ClassLength:
45
+ Enabled: false
46
+
47
+ Metrics/BlockLength:
48
+ Enabled: false
49
+
50
+ Metrics/AbcSize:
51
+ Max: 20
52
+
53
+ Metrics/CyclomaticComplexity:
54
+ Enabled: true
55
+ Max: 10
56
+
57
+ Lint/BooleanSymbol:
58
+ Enabled: false
59
+
60
+ Style/AccessModifierDeclarations:
61
+ Enabled: false
62
+
63
+ Style/BlockDelimiters:
64
+ Enabled: false
65
+
66
+ Layout/IndentFirstArrayElement:
67
+ EnforcedStyle: consistent
68
+
69
+ Style/ClassAndModuleChildren:
70
+ Exclude:
71
+ - "spec/**/*_spec.rb"
72
+
73
+ Lint/HandleExceptions:
74
+ Exclude:
75
+ - "spec/spec_helper.rb"
76
+
77
+ Naming/PredicateName:
78
+ Enabled: false
79
+
80
+ Naming/FileName:
81
+ Exclude:
82
+ - "lib/dry-*.rb"
83
+
84
+ Style/SymbolArray:
85
+ Exclude:
86
+ - "spec/**/*_spec.rb"
87
+
88
+ Style/ConditionalAssignment:
89
+ Enabled: false
90
+
91
+ Naming/MethodName:
92
+ Enabled: false
93
+
94
+ Style/AsciiComments:
95
+ Enabled: false
96
+
97
+ Style/DateTime:
98
+ Enabled: false
99
+
100
+ Style/IfUnlessModifier:
101
+ Enabled: false
@@ -1,23 +1,76 @@
1
+ # v1.3.5 2020-01-06
2
+
3
+ ## Added
4
+
5
+ - Smarter keys deconstruction in pattern matching (flash-gordon)
6
+
7
+ [Compare v1.3.4...v1.3.5](https://github.com/dry-rb/dry-monads/compare/v1.3.4...v1.3.5)
8
+
9
+ # v1.3.4 2019-12-28
10
+
11
+ ## Fixed
12
+
13
+ - One more delegation warning happenning in do notation (flash-gordon)
14
+
15
+ [Compare v1.3.3...v1.3.4](https://github.com/dry-rb/dry-monads/compare/v1.3.3...v1.3.4)
16
+
17
+ # v1.3.3 2019-12-11
18
+
19
+ ## Fixed
20
+
21
+ - 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
+
23
+ [Compare v1.3.2...v1.3.3](https://github.com/dry-rb/dry-monads/compare/v1.3.2...v1.3.3)
24
+
25
+ # v1.3.2 2019-11-30
26
+
27
+ ## Fixed
28
+
29
+ - Warnings about keywords from Ruby 2.7 (flash-gordon)
30
+
31
+ ## Added
32
+
33
+ - 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
+ ```ruby
35
+ case result
36
+ in Success(code: 200...300) then :ok
37
+ end
38
+ ```
39
+
40
+ ## Internal
41
+
42
+ - Performance of do notation was improved for failing cases (1.2x to 1.3x on synthetic benchmarks) (flash-gordon)
43
+
44
+ [Compare v1.3.1...v1.3.2](https://github.com/dry-rb/dry-monads/compare/v1.3.1...v1.3.2)
45
+
46
+ # v1.3.1 2019-09-07
47
+
48
+ ## Fixed
49
+
50
+ - Added missing `None#maybe` :sweat_smile: (flash-gordon)
51
+
52
+ [Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-monads/compare/v1.3.0...v1.3.1)
53
+
1
54
  # v1.3.0 2019-08-03
2
55
 
3
56
  ## BREAKING CHANGES
4
57
 
5
- * Support for Ruby 2.3 was dropped.
58
+ - Support for Ruby 2.3 was dropped.
6
59
 
7
60
  ## Added
8
61
 
9
- * `Result#either` (waiting-for-dev)
62
+ - `Result#either` (waiting-for-dev)
10
63
  ```ruby
11
64
  Success(1).either(-> x { x + 1 }, -> x { x + 2 }) # => 2
12
65
  Failure(1).either(-> x { x + 1 }, -> x { x + 2 }) # => 3
13
66
  ```
14
- * `Maybe#to_result` (SpyMachine + flash-gordon)
67
+ - `Maybe#to_result` (SpyMachine + flash-gordon)
15
68
  ```ruby
16
69
  Some(3).to_result(:no_value) # => Success(3)
17
70
  None().to_result { :no_value } # => Failure(:no_value)
18
71
  None().to_result # => Failure()
19
72
  ```
20
- * Do notation can be used with `extend`. This simplifies usage in class methods and in other "complicated" cases (gogiel + flash-gordon)
73
+ - Do notation can be used with `extend`. This simplifies usage in class methods and in other "complicated" cases (gogiel + flash-gordon)
21
74
 
22
75
  ```ruby
23
76
  class CreateUser
@@ -34,24 +87,27 @@
34
87
  end
35
88
  end
36
89
  ```
37
-
90
+
38
91
  Or you can bind values directly:
92
+
39
93
  ```ruby
40
94
  ma = Dry::Monads.Success(1)
41
95
  mb = Dry::Monads.Success(2)
42
-
96
+
43
97
  Dry::Monads::Do.() do
44
98
  a = Dry::Monads::Do.bind(ma)
45
99
  b = Dry::Monads::Do.bind(mb)
46
-
100
+
47
101
  Dry::Monads.Success(a + b)
48
102
  end
49
103
  ```
50
- * `{Some,Success,Failure}#[]` shortcuts for building arrays wrapped within monadic value (flash-gordon)
104
+
105
+ - `{Some,Success,Failure}#[]` shortcuts for building arrays wrapped within monadic value (flash-gordon)
51
106
  ```ruby
52
- Success[1, 2] # => Success([1, 2])
107
+ Success[1, 2] # => Success([1, 2])
53
108
  ```
54
- * `List.unfold` yields a block returning `Maybe<Any>`. If the block returns `Some(a)` `a` is appended to the output list. Returning `None` halts the unfloding (flash-gordon)
109
+ - `List.unfold` yields a block returning `Maybe<Any>`. If the block returns `Some(a)` `a` is appended to the output list. Returning `None` halts the unfloding (flash-gordon)
110
+
55
111
  ```ruby
56
112
  List.unfold(0) do |x|
57
113
  if x > 5
@@ -61,8 +117,9 @@
61
117
  end
62
118
  end # => List[1, 2, 3, 4, 5]
63
119
  ```
64
-
65
- * Experimental support for pattern matching! :tada: (flash-gordon)
120
+
121
+ - Experimental support for pattern matching! :tada: (flash-gordon)
122
+
66
123
  ```ruby
67
124
  case value
68
125
  in Failure(_) then :failure
@@ -75,28 +132,31 @@
75
132
  in Success({ code: 200..300 => x }) then x
76
133
  end
77
134
  ```
78
- Read more about pattern matching in Ruby:
135
+
136
+ Read more about pattern matching in Ruby:
137
+
79
138
  - https://medium.com/@baweaver/ruby-2-7-pattern-matching-destructuring-on-point-90f56aaf7b4e
80
139
  - https://bugs.ruby-lang.org/issues/14912
81
-
140
+
82
141
  Keep in mind this feature is experimental and can be changed by 2.7 release. But it rocks already!
83
-
142
+
84
143
  [Compare v1.2.0...v1.3.0](https://github.com/dry-rb/dry-monads/compare/v1.2.0...v1.3.0)
85
144
 
86
145
  # v1.2.0 2019-01-12
87
146
 
88
147
  ## BREAKING CHANGES
89
148
 
90
- * Support for Ruby 2.2 was dropped. Ruby 2.2 reached its EOL on March 31, 2018.
149
+ - Support for Ruby 2.2 was dropped. Ruby 2.2 reached its EOL on March 31, 2018.
91
150
 
92
151
  ## Added
93
152
 
94
- * 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)
153
+ - 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)
95
154
  ```ruby
96
155
  pipe = -> x { x.upcase } >> Success
97
156
  pipe.('foo') # => Success('FOO')
98
157
  ```
99
- * `List#collect` gathers `Some` values from the list (flash-gordon)
158
+ - `List#collect` gathers `Some` values from the list (flash-gordon)
159
+
100
160
  ```ruby
101
161
  include Dry::Monads::List::Mixin
102
162
  include Dry::Monads::Maybe::Mixin
@@ -118,9 +178,10 @@
118
178
  # => [10, 6]
119
179
  ```
120
180
 
121
- * Right-biased monads got `#flatten` and `#and` (falsh-gordon)
181
+ - Right-biased monads got `#flatten` and `#and` (falsh-gordon)
122
182
 
123
183
  `#flatten` removes one level of monadic structure, it's useful when you're dealing with things like `Maybe` of `Maybe` of something:
184
+
124
185
  ```ruby
125
186
  include Dry::Monads::Maybe::Mixin
126
187
 
@@ -128,11 +189,15 @@
128
189
  Some(None()).flatten # => None
129
190
  None().flatten # => None
130
191
  ```
192
+
131
193
  In contrast to `Array#flatten`, dry-monads' version removes only 1 level of nesting, that is always acts as `Array#flatten(1)`:
194
+
132
195
  ```ruby
133
196
  Some(Some(Some(1))).flatten # => Some(Some(1))
134
197
  ```
198
+
135
199
  `#and` is handy for combining two monadic values and working with them at once:
200
+
136
201
  ```ruby
137
202
  include Dry::Monads::Maybe::Mixin
138
203
 
@@ -145,7 +210,7 @@
145
210
  None().and(Some(5)) # => None()
146
211
  ```
147
212
 
148
- * 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)
213
+ - 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)
149
214
 
150
215
  ```ruby
151
216
  require 'dry/monads'
@@ -169,7 +234,8 @@
169
234
  end
170
235
  end
171
236
  ```
172
- * `Task.failed` is a counterpart of `Task.pure`, accepts an exception and returns a failed task immediately (flash-gordon)
237
+
238
+ - `Task.failed` is a counterpart of `Task.pure`, accepts an exception and returns a failed task immediately (flash-gordon)
173
239
 
174
240
  [Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-monads/compare/v1.1.0...v1.2.0)
175
241
 
@@ -177,11 +243,12 @@
177
243
 
178
244
  ## Fixed
179
245
 
180
- * Do notation was made to work nicely with inheritance. This shouldn't break any existing code but if it does please report (flash-gordon)
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)
181
247
 
182
248
  ## Added
183
249
 
184
- * `Success()`, `Failure()`, and `Some()` now have `Unit` as a default argument:
250
+ - `Success()`, `Failure()`, and `Some()` now have `Unit` as a default argument:
251
+
185
252
  ```ruby
186
253
  include Dry::Monads::Result::Mixin
187
254
  include Dry::Monads::Do
@@ -200,11 +267,11 @@
200
267
 
201
268
  ## Fixed
202
269
 
203
- * Fixed behavior of `List<Validated>#traverse` in presence of `Valid` values (flash-gordon + SunnyMagadan)
270
+ - Fixed behavior of `List<Validated>#traverse` in presence of `Valid` values (flash-gordon + SunnyMagadan)
204
271
 
205
272
  ## Added
206
273
 
207
- * `to_proc` was added to value constructors (flash-gordon)
274
+ - `to_proc` was added to value constructors (flash-gordon)
208
275
  ```ruby
209
276
  [1, 2, 3].map(&Some) # => [Some(1), Some(2), Some(3)]
210
277
  ```
@@ -215,7 +282,7 @@
215
282
 
216
283
  ## Added
217
284
 
218
- * `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:
285
+ - `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:
219
286
 
220
287
  ```ruby
221
288
  class CreateUser
@@ -266,7 +333,7 @@
266
333
 
267
334
  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)
268
335
 
269
- * 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)
336
+ - 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)
270
337
 
271
338
  ```ruby
272
339
  include Dry::Monads::Task::Mixin
@@ -292,9 +359,9 @@
292
359
  end
293
360
  ```
294
361
 
295
- * `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)
362
+ - `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)
296
363
 
297
- * Automatic type inference with `.typed` for lists was deprecated. Instead, typed list builders were added
364
+ - Automatic type inference with `.typed` for lists was deprecated. Instead, typed list builders were added
298
365
 
299
366
  ```ruby
300
367
  list = List::Task[Task { get_name }, Task { get_email }]
@@ -303,7 +370,7 @@
303
370
 
304
371
  The code above runs two tasks in parallel and automatically combines their results with `traverse` (flash-gordon)
305
372
 
306
- * `Try` got a new call syntax supported in Ruby 2.5+
373
+ - `Try` got a new call syntax supported in Ruby 2.5+
307
374
 
308
375
  ```ruby
309
376
  Try[ArgumentError, TypeError] { unsafe_operation }
@@ -311,7 +378,7 @@
311
378
 
312
379
  Prior to 2.5, it wasn't possible to pass a block to `[]`.
313
380
 
314
- * 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.
381
+ - 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.
315
382
 
316
383
  ```ruby
317
384
  include Dry::Monads
@@ -335,13 +402,13 @@
335
402
 
336
403
  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).
337
404
 
338
- * `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
405
+ - `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
339
406
 
340
407
  ```ruby
341
408
  Failure(:invalid_name).trace # => app/operations/create_user.rb:43
342
409
  ```
343
410
 
344
- * `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`.
411
+ - `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`.
345
412
 
346
413
  ```ruby
347
414
  # we're making an HTTP request but "forget" any successful result,
@@ -353,12 +420,12 @@
353
420
 
354
421
  ## Deprecations
355
422
 
356
- * `Either`, the former name of `Result`, is now deprecated
423
+ - `Either`, the former name of `Result`, is now deprecated
357
424
 
358
425
  ## BREAKING CHANGES
359
426
 
360
- * `Either#value` and `Maybe#value` were both droped, use `value_or` or `value!` when you :100: sure it's safe
361
- * `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)
427
+ - `Either#value` and `Maybe#value` were both droped, use `value_or` or `value!` when you :100: sure it's safe
428
+ - `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)
362
429
 
363
430
  [Compare v0.4.0...v1.0.0](https://github.com/dry-rb/dry-monads/compare/v0.4.0...v1.0.0)
364
431
 
@@ -366,16 +433,16 @@
366
433
 
367
434
  ## Changed
368
435
 
369
- * 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)
370
- * Consequently, `Try::Success` and `Try::Failure` were renamed to `Try::Value` and `Try::Error` (flash-gordon)
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)
371
438
 
372
439
  ## Added
373
440
 
374
- * `Try#or`, works as `Result#or` (flash-gordon)
375
- * `Maybe#success?` and `Maybe#failure?` (aliases for `#some?` and `#none?`) (flash-gordon)
376
- * `Either#flip` inverts a `Result` value (flash-gordon)
377
- * `List#map` called without a block returns an `Enumerator` object (flash-gordon)
378
- * Right-biased monads (`Maybe`, `Result`, and `Try`) now implement the `===` operator which is used for equality checks in the `case` statement (flash-gordon)
441
+ - `Try#or`, works as `Result#or` (flash-gordon)
442
+ - `Maybe#success?` and `Maybe#failure?` (aliases for `#some?` and `#none?`) (flash-gordon)
443
+ - `Either#flip` inverts a `Result` value (flash-gordon)
444
+ - `List#map` called without a block returns an `Enumerator` object (flash-gordon)
445
+ - Right-biased monads (`Maybe`, `Result`, and `Try`) now implement the `===` operator which is used for equality checks in the `case` statement (flash-gordon)
379
446
  ```ruby
380
447
  case value
381
448
  when Some(1..100) then :ok
@@ -387,7 +454,7 @@
387
454
 
388
455
  ## Deprecated
389
456
 
390
- * 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)
457
+ - 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)
391
458
 
392
459
  [Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-monads/compare/v0.3.1...v0.4.0)
393
460
 
@@ -395,20 +462,21 @@
395
462
 
396
463
  ## Fixed
397
464
 
398
- * Fixed unexpected coercing to `Hash` on `.bind` call (flash-gordon)
465
+ - Fixed unexpected coercing to `Hash` on `.bind` call (flash-gordon)
399
466
 
400
467
  [Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-monads/compare/v0.3.0...v0.3.1)
401
468
 
402
469
  # v0.3.0 2017-03-16
403
470
 
404
471
  ## Added
405
- * Added `Either#either` that accepts two callbacks, runs the first if it is `Right` and the second otherwise (nkondratyev)
406
- * Added `#fmap2` and `#fmap3` for mapping over nested structures like `List Either` and `Either Some` (flash-gordon)
407
- * Added `Try#value_or` (dsounded)
408
- * Added the `List` monad which acts as an immutable `Array` and plays nice with other monads. A common example is a list of `Either`s (flash-gordon)
409
- * `#bind` made to work with keyword arguments as extra parameters to the block (flash-gordon)
410
- * Added `List#traverse` that "flips" the list with an embedded monad (flash-gordon + damncabbage)
411
- * Added `#tee` for all right-biased monads (flash-gordon)
472
+
473
+ - Added `Either#either` that accepts two callbacks, runs the first if it is `Right` and the second otherwise (nkondratyev)
474
+ - Added `#fmap2` and `#fmap3` for mapping over nested structures like `List Either` and `Either Some` (flash-gordon)
475
+ - Added `Try#value_or` (dsounded)
476
+ - Added the `List` monad which acts as an immutable `Array` and plays nice with other monads. A common example is a list of `Either`s (flash-gordon)
477
+ - `#bind` made to work with keyword arguments as extra parameters to the block (flash-gordon)
478
+ - Added `List#traverse` that "flips" the list with an embedded monad (flash-gordon + damncabbage)
479
+ - Added `#tee` for all right-biased monads (flash-gordon)
412
480
 
413
481
  [Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-monads/compare/v0.2.1...v0.3.0)
414
482
 
@@ -416,12 +484,12 @@
416
484
 
417
485
  ## Added
418
486
 
419
- * Added `Either#tee` that is similar to `Object#tap` but executes the block only for `Right` instances (saverio-kantox)
487
+ - Added `Either#tee` that is similar to `Object#tap` but executes the block only for `Right` instances (saverio-kantox)
420
488
 
421
489
  ## Fixed
422
490
 
423
- * `Right(nil).to_maybe` now returns `None` with a warning instead of failing (orisaka)
424
- * `Some#value_or` doesn't require an argument because `None#value_or` doesn't require it either if a block was passed (flash-gordon)
491
+ - `Right(nil).to_maybe` now returns `None` with a warning instead of failing (orisaka)
492
+ - `Some#value_or` doesn't require an argument because `None#value_or` doesn't require it either if a block was passed (flash-gordon)
425
493
 
426
494
  [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-monads/compare/v0.2.0...v0.2.1)
427
495
 
@@ -429,8 +497,8 @@
429
497
 
430
498
  ## Added
431
499
 
432
- * Added `Maybe#to_json` as an opt-in extension for serialization to JSON (rocknruby)
433
- * Added `Maybe#value_or` which returns you the underlying value with a fallback in a single method call (dsounded)
500
+ - Added `Maybe#to_json` as an opt-in extension for serialization to JSON (rocknruby)
501
+ - Added `Maybe#value_or` which returns you the underlying value with a fallback in a single method call (dsounded)
434
502
 
435
503
  [Compare v0.1.1...v0.2.0](https://github.com/dry-rb/dry-monads/compare/v0.1.1...v0.2.0)
436
504
 
@@ -438,7 +506,7 @@
438
506
 
439
507
  ## Fixed
440
508
 
441
- * Added explicit requires of `dry-equalizer`. This allows to safely load only specific monads (artofhuman)
509
+ - Added explicit requires of `dry-equalizer`. This allows to safely load only specific monads (artofhuman)
442
510
 
443
511
  [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-monads/compare/v0.1.0...v0.1.1)
444
512
 
@@ -446,11 +514,11 @@
446
514
 
447
515
  ## Added
448
516
 
449
- * Support for passing extra arguments to the block in `.bind` and `.fmap` (flash-gordon)
517
+ - Support for passing extra arguments to the block in `.bind` and `.fmap` (flash-gordon)
450
518
 
451
519
  ## Changed
452
520
 
453
- * Dropped MRI 2.0 support (flash-gordon)
521
+ - Dropped MRI 2.0 support (flash-gordon)
454
522
 
455
523
  [Compare v0.0.2...v0.1.0](https://github.com/dry-rb/dry-monads/compare/v0.0.2...v0.1.0)
456
524
 
@@ -458,8 +526,8 @@
458
526
 
459
527
  ## Added
460
528
 
461
- * Added `Either#to_either` so that you can rely on duck-typing when you work with different types of monads (timriley)
462
- * Added `Maybe#to_maybe` for consistency with `#to_either` (flash-gordon)
529
+ - Added `Either#to_either` so that you can rely on duck-typing when you work with different types of monads (timriley)
530
+ - Added `Maybe#to_maybe` for consistency with `#to_either` (flash-gordon)
463
531
 
464
532
  [Compare v0.0.1...v0.0.2](https://github.com/dry-rb/dry-monads/compare/v0.0.1...v0.0.2)
465
533