dry-monads 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1408f096fd2a997f68c0ac8f7086eca73b3f493ffab9c2992d9ebaf52418b0e4
4
- data.tar.gz: 0c967ca1adcaaf66813f15e92c1391abe681e8e1d0c4ae9c4ea68069b7a915d8
3
+ metadata.gz: 86fbad001116e7a69e01b2f7e8b0c5ee8101a95af73fd9f485880131df364749
4
+ data.tar.gz: 5d3a4bf072bfcfe22edb31512a4b29b5952c7aaa674af4b1ef546dc8ce39e302
5
5
  SHA512:
6
- metadata.gz: a9f8b2abd8d7a92bb56c7160c0c42c8dc594d4130c874ce79d5d67a2fe827f383353244129b033ad1ba601d20d80ccbe5aebe8b1c4378cbd181a6f532353fa12
7
- data.tar.gz: 34d09d33244f4feb8a26fbc91bf66ee02d085e00b33e5cbc3cbcc3c23059478cfc59c2ba5c79e0fb344a4ca543d17f863e374bba11a342d42bff8713723146e8
6
+ metadata.gz: aaa55a8f21b5e84d9b4029a59733a72c4bd21ccfd76430faa4eb39c821860e774e0a94e9fddbecd66a6e0c9c876d7178dc66a2364b85851ecbf56fb8b6ac5e86
7
+ data.tar.gz: 126cc641f1ba8ba33fd251e63d18668c1360eff70967f86705a333fcd01df95cc3909579a128e270629b4609179db435fdeb0de0d3a5fcdb2ef0693ccc3fcc49
@@ -8,69 +8,45 @@ on:
8
8
  - .github/workflows/ci.yml
9
9
  - lib/**
10
10
  - spec/**
11
+ - Rakefile
11
12
  - Gemfile
13
+ - Gemfile.devtools
12
14
  - "*.gemspec"
15
+ - ".rubocop.yml"
16
+ pull_request:
17
+ branches:
18
+ - master
13
19
 
14
20
  jobs:
15
- tests-mri:
21
+ tests:
16
22
  runs-on: ubuntu-latest
17
23
  strategy:
18
24
  fail-fast: false
19
25
  matrix:
20
- ruby: ["2.6.x", "2.5.x", "2.4.x"]
26
+ ruby:
27
+ - "2.7"
28
+ - "2.6"
29
+ - "2.5"
30
+ - "2.4"
31
+ - "jruby"
21
32
  include:
22
- - ruby: "2.6.x"
33
+ - ruby: "2.6"
23
34
  coverage: "true"
24
35
  steps:
25
36
  - uses: actions/checkout@v1
26
37
  - name: Set up Ruby
27
- uses: actions/setup-ruby@v1
38
+ uses: eregon/use-ruby-action@master
28
39
  with:
29
40
  ruby-version: ${{matrix.ruby}}
30
- - name: Download test reporter
31
- if: "matrix.coverage == 'true'"
32
- run: |
33
- mkdir -p tmp/
34
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
35
- chmod +x ./tmp/cc-test-reporter
36
- ./tmp/cc-test-reporter before-build
37
- - name: Bundle install
41
+ - name: Install latest bundler
38
42
  run: |
39
43
  gem install bundler
40
- bundle install --jobs 4 --retry 3 --without tools docs benchmarks
44
+ bundle config set without 'tools benchmarks docs'
45
+ - name: Bundle install
46
+ run: bundle install --jobs 4 --retry 3
41
47
  - name: Run all tests
42
48
  env:
43
49
  COVERAGE: ${{matrix.coverage}}
44
- run: bundle exec rake
45
- - name: Send coverage results
46
- if: "matrix.coverage == 'true'"
47
- env:
48
- CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
49
- GIT_COMMIT_SHA: ${{github.sha}}
50
- GIT_BRANCH: ${{github.ref}}
51
- GIT_COMMITTED_AT: ${{github.event.head_commit.timestamp}}
52
- run: |
53
- GIT_BRANCH=`ruby -e "puts ENV['GITHUB_REF'].split('/', 3).last"` \
54
- GIT_COMMITTED_AT=`ruby -r time -e "puts Time.iso8601(ENV['GIT_COMMITTED_AT']).to_i"` \
55
- ./tmp/cc-test-reporter after-build
56
-
57
- tests-others:
58
- runs-on: ubuntu-latest
59
- strategy:
60
- fail-fast: false
61
- matrix:
62
- image: ["jruby:9.2.9", "ruby:2.7"]
63
- container:
64
- image: ${{matrix.image}}
65
- steps:
66
- - uses: actions/checkout@v1
67
- - name: Install git
68
- run: |
69
- apt-get update
70
- apt-get install -y --no-install-recommends git
71
- - name: Bundle install
72
- run: |
73
- gem install bundler
74
- bundle install --jobs 4 --retry 3 --without tools docs benchmarks
75
- - name: Run all tests
50
+ CODACY_RUN_LOCAL: true
51
+ CODACY_PROJECT_TOKEN: ${{secrets.CODACY_PROJECT_TOKEN}}
76
52
  run: bundle exec rake
@@ -11,23 +11,45 @@ jobs:
11
11
  if: github.event.action == 'sync_configs'
12
12
  steps:
13
13
  - uses: actions/checkout@v1
14
- - name: Update configuration files from devtools
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
15
29
  env:
16
30
  GITHUB_LOGIN: dry-bot
17
31
  GITHUB_TOKEN: ${{ secrets.GH_PAT }}
18
32
  run: |
19
- git clone https://github.com/dry-rb/devtools.git tmp/devtools
20
-
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: |
21
41
  if [ -f ".github/workflows/custom_ci.yml" ]; then
22
- rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
42
+ rsync -arv --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
23
43
  else
24
- rsync -av tmp/devtools/shared/ . ;
44
+ rsync -arv tmp/devtools/shared/ . ;
25
45
  fi
26
-
46
+ - name: Commit changes
47
+ run: |
48
+ rm bin/ossy
27
49
  git config --local user.email "dry-bot@dry-rb.org"
28
50
  git config --local user.name "dry-bot"
29
51
  git add -A
30
- git commit -m "[devtools] config sync" || echo "nothing changed"
52
+ git commit -m "[devtools] sync configs" || echo "nothing changed"
31
53
  - name: Push changes
32
54
  uses: ad-m/github-push-action@master
33
55
  with:
data/.rspec CHANGED
@@ -1,4 +1,4 @@
1
1
  --color
2
2
  --require spec_helper
3
3
  --order random
4
-
4
+ --warnings
@@ -10,6 +10,9 @@ Style/StringLiterals:
10
10
  Enabled: true
11
11
  EnforcedStyle: single_quotes
12
12
 
13
+ Style/ParallelAssignment:
14
+ Enabled: false
15
+
13
16
  Style/Alias:
14
17
  Enabled: false
15
18
 
@@ -36,17 +39,17 @@ Metrics/LineLength:
36
39
  Max: 100
37
40
 
38
41
  Metrics/MethodLength:
39
- Max: 22
42
+ Enabled: false
40
43
 
41
44
  Metrics/ClassLength:
42
- Max: 150
43
-
44
- Metrics/AbcSize:
45
- Max: 20
45
+ Enabled: false
46
46
 
47
47
  Metrics/BlockLength:
48
48
  Enabled: false
49
49
 
50
+ Metrics/AbcSize:
51
+ Max: 20
52
+
50
53
  Metrics/CyclomaticComplexity:
51
54
  Enabled: true
52
55
  Max: 10
@@ -71,6 +74,9 @@ Lint/HandleExceptions:
71
74
  Exclude:
72
75
  - "spec/spec_helper.rb"
73
76
 
77
+ Naming/PredicateName:
78
+ Enabled: false
79
+
74
80
  Naming/FileName:
75
81
  Exclude:
76
82
  - "lib/dry-*.rb"
@@ -1,3 +1,11 @@
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
+
1
9
  # v1.3.4 2019-12-28
2
10
 
3
11
  ## Fixed
data/Gemfile CHANGED
@@ -1,23 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
+ eval_gemfile 'Gemfile.devtools'
4
6
 
5
7
  gemspec
6
8
 
7
- group :test do
8
- gem 'simplecov', require: false
9
- gem 'warning'
10
- end
11
-
12
9
  group :tools do
13
- gem 'pry-byebug', platform: :mri
14
- gem 'pry', platform: :jruby
15
- gem 'ossy', github: 'solnic/ossy', branch: 'master'
16
10
  gem 'benchmark-ips'
11
+ gem 'pry', platform: :jruby
12
+ gem 'pry-byebug', platform: :mri
17
13
  end
18
14
 
19
15
  group :docs do
16
+ gem 'redcarpet'
20
17
  gem 'yard'
21
18
  gem 'yard-junk'
22
- gem 'redcarpet'
23
19
  end
@@ -0,0 +1,14 @@
1
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
2
+
3
+ gem "ossy", github: "solnic/ossy", branch: "master", platforms: :ruby
4
+
5
+ group :test do
6
+ gem 'codacy-coverage', require: false, platforms: :ruby
7
+ gem 'simplecov', require: false, platforms: :ruby
8
+ gem 'warning'
9
+ end
10
+
11
+ group :tools do
12
+ # this is the same version that we use on codacy
13
+ gem 'rubocop', '0.71.0'
14
+ end
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 dry-rb team
3
+ Copyright (c) 2015-2020 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,49 +1,29 @@
1
1
  [gem]: https://rubygems.org/gems/dry-monads
2
- [ci]: https://github.com/dry-rb/dry-monads/actions?query=workflow%3Aci
3
- [code_climate]: https://codeclimate.com/github/dry-rb/dry-monads
4
- [inch]: http://inch-ci.org/github/dry-rb/dry-monads
2
+ [actions]: https://github.com/dry-rb/dry-monads/actions
3
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-monads
5
4
  [chat]: https://dry-rb.zulipchat.com
5
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-monads
6
6
 
7
7
  # dry-monads [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
- [![Gem Version](https://img.shields.io/gem/v/dry-monads.svg)][gem]
10
- [![Build Status](https://github.com/dry-rb/dry-monads/workflows/ci/badge.svg)][ci]
11
- [![Code Climate](https://api.codeclimate.com/v1/badges/b0ea4d8023d53b7f0f50/maintainability)][code_climate]
12
- [![Test Coverage](https://api.codeclimate.com/v1/badges/b0ea4d8023d53b7f0f50/test_coverage)][code_climate]
13
- [![API Documentation Coverage](http://inch-ci.org/github/dry-rb/dry-monads.svg)][inch]
14
-
15
- Monads for Ruby.
16
-
17
- ## Installation
18
-
19
- Add this line to your application's Gemfile:
20
-
21
- ```ruby
22
- gem 'dry-monads'
23
- ```
24
-
25
- And then execute:
26
-
27
- ```sh
28
- $ bundle
29
- ```
30
-
31
- Or install it yourself as:
32
-
33
- ```sh
34
- $ gem install dry-monads
35
- ```
9
+ [![Gem Version](https://badge.fury.io/rb/dry-monads.svg)][gem]
10
+ [![CI Status](https://github.com/dry-rb/dry-monads/workflows/ci/badge.svg)][actions]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f2eed41bf7f04b38b0a7691c2cf6e73c)][codacy]
12
+ [![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=master)][inchpages]
36
14
 
37
15
  ## Links
38
16
 
39
- - [Documentation](http://dry-rb.org/gems/dry-monads)
17
+ * [User documentation](http://dry-rb.org/gems/dry-monads)
18
+ * [API documentation](http://rubydoc.info/gems/dry-monads)
19
+
20
+ ## Supported Ruby versions
40
21
 
41
- ## Development
22
+ This library officially supports the following Ruby versions:
42
23
 
43
- After checking out the repo, run `bin/setup` to install dependencies. Then, run
44
- `rake spec` to run the tests. You can also run `bin/console` for an interactive
45
- prompt that will allow you to experiment.
24
+ * MRI >= `2.4`
25
+ * jruby >= `9.2`
46
26
 
47
- ## Contributing
27
+ ## License
48
28
 
49
- Bug reports and pull requests are welcome on GitHub at <https://github.com/dry-rb/dry-monads>.
29
+ See `LICENSE` file.
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
File without changes
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'dry/monads/all'
@@ -4,7 +4,7 @@ layout: gem-single
4
4
  name: dry-monads
5
5
  ---
6
6
 
7
- Ruby 2.7 introduces pattern matchings, it is nicely supported by dry-monads 1.3+.
7
+ Ruby 2.7 introduces pattern matching, it is nicely supported by dry-monads 1.3+.
8
8
 
9
9
  ### Matching Result values
10
10
 
@@ -22,10 +22,10 @@ in Success([1, *])
22
22
  # any array starting with 1
23
23
  in Success(String => s) if s.size < 100
24
24
  # only if `s` is short enough
25
- in Success({ counter: Integer })
25
+ in Success(counter: Integer)
26
26
  # matches Success(counter: 50)
27
27
  # doesn't match Success(counter: 50, extra: 50)
28
- in Success({ user: User, account: Account => user_account, ** })
28
+ in Success(user: User, account: Account => user_account)
29
29
  # matches Success(user: User.new(...), account: Account.new(...), else: ...)
30
30
  # user_account is bound to the value of the `:account` key
31
31
  in Success()
@@ -45,8 +45,8 @@ In the sippet above, the patterns will be tried sequentially. If `value` doesn't
45
45
 
46
46
  ```ruby
47
47
  case value
48
- in Some(Integer => x)
49
- # x is an integer
48
+ in Some(Integer => x) if x > 0
49
+ # x is a positive integer
50
50
  in Some(Float | String)
51
51
  # ...
52
52
  in None
@@ -1,4 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'dry/monads/version'
4
6
 
@@ -25,13 +27,13 @@ Gem::Specification.new do |spec|
25
27
  spec.bindir = 'exe'
26
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
29
  spec.require_paths = ['lib']
28
- spec.required_ruby_version = ">= 2.4.0"
29
- spec.add_dependency 'dry-equalizer'
30
- spec.add_dependency 'dry-core', '~> 0.4', '>= 0.4.4'
30
+ spec.required_ruby_version = '>= 2.4.0'
31
31
  spec.add_dependency 'concurrent-ruby', '~> 1.0'
32
+ spec.add_dependency 'dry-core', '~> 0.4', '>= 0.4.4'
33
+ spec.add_dependency 'dry-equalizer'
32
34
 
33
35
  spec.add_development_dependency 'bundler'
36
+ spec.add_development_dependency 'dry-types', '>= 0.12'
34
37
  spec.add_development_dependency 'rake'
35
38
  spec.add_development_dependency 'rspec'
36
- spec.add_development_dependency 'dry-types', '>= 0.12'
37
39
  end
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/constants'
2
4
  require 'dry/monads/registry'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads'
2
4
  require 'dry/monads/registry'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Monads
3
5
  module ConversionStubs
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Monads
3
5
  # @private
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads/list'
2
4
  require 'dry/monads/do/mixin'
3
5
  require 'dry/monads/constants'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads/do'
2
4
 
3
5
  module Dry
@@ -119,6 +121,7 @@ module Dry
119
121
  super(method)
120
122
 
121
123
  next if method.equal?(:singleton_method_added)
124
+
122
125
  Do.wrap_method(wrapper, method)
123
126
  end
124
127
  object.singleton_class.instance_methods(false).each do |m|
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Monads
3
5
  module Do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/core/deprecations'
2
4
 
3
5
  Dry::Core::Deprecations.warn('Either monad was renamed to Result', tag: :'dry-monads')
@@ -1,16 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Monads
3
5
  # An unsuccessful result of extracting a value from a monad.
4
6
  class UnwrapError < StandardError
5
7
  def initialize(ctx)
6
- super("value! was called on #{ ctx.inspect }")
8
+ super("value! was called on #{ctx.inspect}")
7
9
  end
8
10
  end
9
11
 
10
12
  # An error thrown on returning a Failure of unknown type.
11
13
  class InvalidFailureTypeError < StandardError
12
14
  def initialize(failure)
13
- super("Cannot create Failure from #{ failure.inspect }, it doesn't meet the constraints")
15
+ super("Cannot create Failure from #{failure.inspect}, it doesn't meet the constraints")
14
16
  end
15
17
  end
16
18
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/promise'
2
4
 
3
5
  require 'dry/monads/task'
@@ -45,12 +47,12 @@ module Dry
45
47
  when :fulfilled
46
48
  value!.inspect
47
49
  when :rejected
48
- "!#{ promise.reason.inspect }"
50
+ "!#{promise.reason.inspect}"
49
51
  else
50
52
  '?'
51
53
  end
52
54
 
53
- "Lazy(#{ state })"
55
+ "Lazy(#{state})"
54
56
  end
55
57
  alias_method :inspect, :to_s
56
58
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
 
3
5
  require 'dry/monads/maybe'
@@ -163,8 +165,8 @@ module Dry
163
165
  #
164
166
  # @return [String]
165
167
  def inspect
166
- type_ann = typed? ? "<#{ type.name.split('::').last }>" : ''
167
- "List#{ type_ann }#{ value.inspect }"
168
+ type_ann = typed? ? "<#{type.name.split('::').last}>" : ''
169
+ "List#{type_ann}#{value.inspect}"
168
170
  end
169
171
  alias_method :to_s, :inspect
170
172
 
@@ -263,10 +265,10 @@ module Dry
263
265
  def typed(type = nil)
264
266
  if type.nil?
265
267
  if size.zero?
266
- raise ArgumentError, "Cannot infer a monad for an empty list"
268
+ raise ArgumentError, 'Cannot infer a monad for an empty list'
267
269
  else
268
270
  self.class.warn(
269
- "Automatic monad inference is deprecated, pass a type explicitly "\
271
+ 'Automatic monad inference is deprecated, pass a type explicitly '\
270
272
  "or use a predefined constant, e.g. List::Result\n"\
271
273
  "#{caller.find { |l| l !~ %r{(lib/dry/monads)|(gems)} }}"
272
274
  )
@@ -296,16 +298,16 @@ module Dry
296
298
  # @return [Monad] Result is a monadic value
297
299
  def traverse(proc = nil, &block)
298
300
  unless typed?
299
- raise StandardError, "Cannot traverse an untyped list"
301
+ raise StandardError, 'Cannot traverse an untyped list'
300
302
  end
301
303
 
302
304
  cons = type.pure { |list, i| list + List.pure(i) }
303
305
  with = proc || block || Traverse[type]
304
306
 
305
307
  foldl(type.pure(EMPTY)) do |acc, el|
306
- cons.
307
- apply(acc).
308
- apply { with.(el) }
308
+ cons
309
+ .apply(acc)
310
+ .apply { with.(el) }
309
311
  end
310
312
  end
311
313
 
@@ -433,7 +435,6 @@ module Dry
433
435
  #
434
436
  # @api public
435
437
  module Mixin
436
-
437
438
  # @see Dry::Monads::List
438
439
  List = List
439
440
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
  require 'dry/core/deprecations'
3
5
 
@@ -104,6 +106,7 @@ module Dry
104
106
 
105
107
  def initialize(value = Undefined)
106
108
  raise ArgumentError, 'nil cannot be some' if value.nil?
109
+
107
110
  @value = Undefined.default(value, Unit)
108
111
  end
109
112
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/map'
2
4
 
3
5
  module Dry
@@ -36,8 +38,9 @@ module Dry
36
38
  # @private
37
39
  def register_mixin(name, mod)
38
40
  if registry.key?(name)
39
- raise ArgumentError, "#{ name.inspect } is already registered"
41
+ raise ArgumentError, "#{name.inspect} is already registered"
40
42
  end
43
+
41
44
  self.registry = registry.merge(name => mod)
42
45
  end
43
46
 
@@ -49,7 +52,7 @@ module Dry
49
52
  # @private
50
53
  def load_monad(name)
51
54
  path = @paths.fetch(name) {
52
- raise ArgumentError, "#{ name.inspect } is not a known monad"
55
+ raise ArgumentError, "#{name.inspect} is not a known monad"
53
56
  }
54
57
  Array(path).each { |p| require p }
55
58
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
 
3
5
  require 'dry/monads/constants'
@@ -299,7 +301,6 @@ module Dry
299
301
  # Value constructors
300
302
  #
301
303
  module Constructors
302
-
303
304
  # Success constructor
304
305
  #
305
306
  # @overload Success(value)
@@ -386,7 +387,7 @@ module Dry
386
387
  # @param fail [#call] Fallback value
387
388
  # @param block [Proc] Fallback block
388
389
  # @return [Success<Any>]
389
- def to_result(fail = Unit, &block)
390
+ def to_result(_fail = Unit)
390
391
  Result::Success.new(@value)
391
392
  end
392
393
  end
@@ -397,7 +398,7 @@ module Dry
397
398
  # @param fail [#call] Fallback value
398
399
  # @param block [Proc] Fallback block
399
400
  # @return [Failure<Any>]
400
- def to_result(fail = Unit, &block)
401
+ def to_result(fail = Unit)
401
402
  if block_given?
402
403
  Result::Failure.new(yield)
403
404
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry::Monads
2
4
  class Result
3
5
  # @see Monads#Result
@@ -7,13 +9,13 @@ module Dry::Monads
7
9
  new(error, **options)
8
10
  end
9
11
 
10
- def initialize(error, **options)
12
+ def initialize(error, **_options)
11
13
  @mod = Module.new do
12
14
  define_method(:Failure) do |value|
13
15
  if error === value
14
16
  Failure.new(value, RightBiased::Left.trace_caller)
15
17
  else
16
- raise InvalidFailureTypeError.new(value)
18
+ raise InvalidFailureTypeError, value
17
19
  end
18
20
  end
19
21
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads/constants'
2
4
  require 'dry/monads/unit'
3
5
  require 'dry/monads/curry'
@@ -118,7 +120,7 @@ module Dry
118
120
  # @return [RightBiased::Left,RightBiased::Right]
119
121
  def apply(val = Undefined)
120
122
  unless @value.respond_to?(:call)
121
- raise TypeError, "Cannot apply #{ val.inspect } to #{ @value.inspect }"
123
+ raise TypeError, "Cannot apply #{val.inspect} to #{@value.inspect}"
122
124
  end
123
125
 
124
126
  Undefined.default(val) { yield }.fmap { |unwrapped| curry.(unwrapped) }
@@ -214,9 +216,9 @@ module Dry
214
216
  # end
215
217
  #
216
218
  # @api private
217
- def deconstruct_keys(_)
218
- if @value.is_a?(::Hash)
219
- @value
219
+ def deconstruct_keys(keys)
220
+ if @value.respond_to?(:deconstruct_keys)
221
+ @value.deconstruct_keys(keys)
220
222
  else
221
223
  EMPTY_HASH
222
224
  end
@@ -258,7 +260,7 @@ module Dry
258
260
 
259
261
  # Raises an error on accessing internal value
260
262
  def value!
261
- raise UnwrapError.new(self)
263
+ raise UnwrapError, self
262
264
  end
263
265
 
264
266
  # Ignores the input parameter and returns self. It exists to keep the interface
@@ -381,9 +383,9 @@ module Dry
381
383
  # end
382
384
  #
383
385
  # @api private
384
- def deconstruct_keys(_)
385
- if @value.is_a?(::Hash)
386
- @value
386
+ def deconstruct_keys(keys)
387
+ if @value.respond_to?(:deconstruct_keys)
388
+ @value.deconstruct_keys(keys)
387
389
  else
388
390
  EMPTY_HASH
389
391
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'concurrent/promise'
2
4
 
3
5
  require 'dry/monads/unit'
@@ -134,7 +136,7 @@ module Dry
134
136
  "value=#{value!.inspect}"
135
137
  end
136
138
  when :rejected
137
- "error=#{ promise.reason.inspect }"
139
+ "error=#{promise.reason.inspect}"
138
140
  else
139
141
  '?'
140
142
  end
@@ -167,11 +169,11 @@ module Dry
167
169
  inner.execute
168
170
  inner.on_success { |r| child.on_fulfill(r) }
169
171
  inner.on_error { |e| child.on_reject(e) }
170
- rescue => e
172
+ rescue StandardError => e
171
173
  child.on_reject(e)
172
174
  end
173
175
  end
174
- promise.on_success { |v| child.on_fulfill(v) }
176
+ promise.on_success { |v| child.on_fulfill(v) }
175
177
 
176
178
  self.class.new(child)
177
179
  end
@@ -200,6 +202,7 @@ module Dry
200
202
  def ==(other)
201
203
  return true if equal?(other)
202
204
  return false unless self.class == other.class
205
+
203
206
  compare_promises(promise, other.promise)
204
207
  end
205
208
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Monads
3
5
  # Advanced tranformations.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads/validated'
2
4
 
3
5
  module Dry
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/equalizer'
2
4
  require 'dry/core/deprecations'
3
5
 
@@ -71,6 +73,7 @@ module Dry
71
73
  # @return [Try::Value,Try::Error]
72
74
  def [](*exceptions, &block)
73
75
  raise ArgumentError, 'At least one exception type required' if exceptions.empty?
76
+
74
77
  run(exceptions, block)
75
78
  end
76
79
  end
@@ -181,7 +184,7 @@ module Dry
181
184
 
182
185
  # @return [String]
183
186
  def to_s
184
- "Try::Error(#{ exception.class }: #{ exception.message })"
187
+ "Try::Error(#{exception.class}: #{exception.message})"
185
188
  end
186
189
  alias_method :inspect, :to_s
187
190
 
@@ -259,6 +262,7 @@ module Dry
259
262
  def Value(value = Undefined, exceptions = DEFAULT_EXCEPTIONS, &block)
260
263
  v = Undefined.default(value, block)
261
264
  raise ArgumentError, 'No value given' if !value.nil? && v.nil?
265
+
262
266
  Value.new(exceptions, v)
263
267
  end
264
268
 
@@ -275,6 +279,7 @@ module Dry
275
279
  def Error(error = Undefined, &block)
276
280
  v = Undefined.default(error, block)
277
281
  raise ArgumentError, 'No value given' if v.nil?
282
+
278
283
  Try::Error.new(v)
279
284
  end
280
285
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dry/monads/conversion_stubs'
2
4
  require 'dry/monads/constants'
3
5
  require 'dry/monads/right_biased'
@@ -49,7 +51,7 @@ module Dry
49
51
  #
50
52
  def bind(*)
51
53
  # See https://typelevel.org/cats/datatypes/validated.html for details on why
52
- raise NotImplementedError, "Validated is not a monad because it would violate the monad laws"
54
+ raise NotImplementedError, 'Validated is not a monad because it would violate the monad laws'
53
55
  end
54
56
 
55
57
  # Valid result
@@ -121,7 +123,7 @@ module Dry
121
123
  # @return [String]
122
124
  def inspect
123
125
  if Unit.equal?(@value)
124
- "Valid()"
126
+ 'Valid()'
125
127
  else
126
128
  "Valid(#{@value.inspect})"
127
129
  end
@@ -167,10 +169,10 @@ module Dry
167
169
  # @return [Validated::Invalid]
168
170
  #
169
171
  def apply(val = Undefined)
170
- Undefined.
171
- default(val) { yield }.
172
- alt_map { |v| @error + v }.
173
- fmap { return self }
172
+ Undefined
173
+ .default(val) { yield }
174
+ .alt_map { |v| @error + v }
175
+ .fmap { return self }
174
176
  end
175
177
 
176
178
  # Lifts a block/proc over Invalid
@@ -211,7 +213,7 @@ module Dry
211
213
 
212
214
  # @return [String]
213
215
  def inspect
214
- "Invalid(#{ @error.inspect })"
216
+ "Invalid(#{@error.inspect})"
215
217
  end
216
218
  alias_method :to_s, :inspect
217
219
 
@@ -225,7 +227,6 @@ module Dry
225
227
  # Mixin with Validated constructors
226
228
  #
227
229
  module Mixin
228
-
229
230
  # Successful validation result
230
231
  # @see Dry::Monads::Validated::Valid
231
232
  Valid = Valid
@@ -250,6 +251,7 @@ module Dry
250
251
  def Valid(value = Undefined, &block)
251
252
  v = Undefined.default(value, block)
252
253
  raise ArgumentError, 'No value given' if !value.nil? && v.nil?
254
+
253
255
  Valid.new(v)
254
256
  end
255
257
 
@@ -266,6 +268,7 @@ module Dry
266
268
  def Invalid(value = Undefined, &block)
267
269
  v = Undefined.default(value, block)
268
270
  raise ArgumentError, 'No value given' if !value.nil? && v.nil?
271
+
269
272
  Invalid.new(v, RightBiased::Left.trace_caller)
270
273
  end
271
274
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Dry
2
4
  module Monads
3
5
  # Gem version
4
- VERSION = '1.3.4'.freeze
6
+ VERSION = '1.3.5'
5
7
  end
6
8
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: false
2
+
2
3
  require 'json' unless defined?(::JSON::JSON_LOADED) && ::JSON::JSON_LOADED
3
4
 
4
5
  require 'dry/monads'
@@ -0,0 +1,2 @@
1
+ name: dry-monads
2
+ codacy_id: f2eed41bf7f04b38b0a7691c2cf6e73c
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-monads
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.4
4
+ version: 1.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nikita Shilnikov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-28 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: dry-equalizer
14
+ name: concurrent-ruby
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dry-core
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -45,19 +45,19 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: 0.4.4
47
47
  - !ruby/object:Gem::Dependency
48
- name: concurrent-ruby
48
+ name: dry-equalizer
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '1.0'
53
+ version: '0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '1.0'
60
+ version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -73,21 +73,21 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: rake
76
+ name: dry-types
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: '0.12'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - ">="
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: '0.12'
89
89
  - !ruby/object:Gem::Dependency
90
- name: rspec
90
+ name: rake
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - ">="
@@ -101,19 +101,19 @@ dependencies:
101
101
  - !ruby/object:Gem::Version
102
102
  version: '0'
103
103
  - !ruby/object:Gem::Dependency
104
- name: dry-types
104
+ name: rspec
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: '0.12'
109
+ version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: '0.12'
116
+ version: '0'
117
117
  description: Common monads for Ruby.
118
118
  email:
119
119
  - fg@flashgordon.ru
@@ -136,9 +136,11 @@ files:
136
136
  - CODE_OF_CONDUCT.md
137
137
  - CONTRIBUTING.md
138
138
  - Gemfile
139
+ - Gemfile.devtools
139
140
  - LICENSE
140
141
  - README.md
141
142
  - Rakefile
143
+ - bin/.gitkeep
142
144
  - bin/console
143
145
  - bin/setup
144
146
  - docsite/source/case-equality.html.md
@@ -182,6 +184,7 @@ files:
182
184
  - lib/dry/monads/version.rb
183
185
  - lib/json/add/dry/monads/maybe.rb
184
186
  - log/.gitkeep
187
+ - project.yml
185
188
  homepage: https://github.com/dry-rb/dry-monads
186
189
  licenses:
187
190
  - MIT