dry-types 1.2.2 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +405 -225
  3. data/LICENSE +1 -1
  4. data/README.md +14 -12
  5. data/dry-types.gemspec +26 -31
  6. data/lib/dry-types.rb +1 -1
  7. data/lib/dry/types.rb +55 -40
  8. data/lib/dry/types/any.rb +2 -2
  9. data/lib/dry/types/array.rb +2 -2
  10. data/lib/dry/types/array/constructor.rb +1 -1
  11. data/lib/dry/types/array/member.rb +1 -1
  12. data/lib/dry/types/builder.rb +70 -18
  13. data/lib/dry/types/builder_methods.rb +1 -2
  14. data/lib/dry/types/coercions.rb +0 -17
  15. data/lib/dry/types/coercions/json.rb +22 -5
  16. data/lib/dry/types/coercions/params.rb +20 -3
  17. data/lib/dry/types/compiler.rb +10 -10
  18. data/lib/dry/types/constrained.rb +6 -9
  19. data/lib/dry/types/constraints.rb +3 -3
  20. data/lib/dry/types/constructor.rb +40 -6
  21. data/lib/dry/types/constructor/function.rb +48 -32
  22. data/lib/dry/types/constructor/wrapper.rb +94 -0
  23. data/lib/dry/types/container.rb +1 -1
  24. data/lib/dry/types/core.rb +15 -13
  25. data/lib/dry/types/decorator.rb +2 -9
  26. data/lib/dry/types/default.rb +14 -1
  27. data/lib/dry/types/enum.rb +4 -3
  28. data/lib/dry/types/errors.rb +1 -1
  29. data/lib/dry/types/extensions.rb +2 -2
  30. data/lib/dry/types/extensions/maybe.rb +18 -17
  31. data/lib/dry/types/extensions/monads.rb +1 -1
  32. data/lib/dry/types/fn_container.rb +1 -1
  33. data/lib/dry/types/hash.rb +9 -15
  34. data/lib/dry/types/hash/constructor.rb +1 -1
  35. data/lib/dry/types/inflector.rb +1 -1
  36. data/lib/dry/types/json.rb +15 -15
  37. data/lib/dry/types/lax.rb +3 -6
  38. data/lib/dry/types/map.rb +2 -2
  39. data/lib/dry/types/meta.rb +3 -3
  40. data/lib/dry/types/module.rb +6 -6
  41. data/lib/dry/types/nominal.rb +11 -11
  42. data/lib/dry/types/params.rb +31 -28
  43. data/lib/dry/types/predicate_inferrer.rb +52 -11
  44. data/lib/dry/types/predicate_registry.rb +1 -1
  45. data/lib/dry/types/primitive_inferrer.rb +1 -1
  46. data/lib/dry/types/printer.rb +25 -25
  47. data/lib/dry/types/result.rb +3 -3
  48. data/lib/dry/types/schema.rb +26 -13
  49. data/lib/dry/types/schema/key.rb +15 -6
  50. data/lib/dry/types/spec/types.rb +65 -42
  51. data/lib/dry/types/sum.rb +6 -5
  52. data/lib/dry/types/type.rb +1 -1
  53. data/lib/dry/types/version.rb +1 -1
  54. metadata +27 -78
  55. data/.codeclimate.yml +0 -12
  56. data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
  57. data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
  58. data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
  59. data/.github/workflows/custom_ci.yml +0 -76
  60. data/.github/workflows/docsite.yml +0 -34
  61. data/.github/workflows/sync_configs.yml +0 -34
  62. data/.gitignore +0 -11
  63. data/.rspec +0 -4
  64. data/.rubocop.yml +0 -92
  65. data/.yardopts +0 -9
  66. data/CODE_OF_CONDUCT.md +0 -13
  67. data/CONTRIBUTING.md +0 -29
  68. data/Gemfile +0 -34
  69. data/Rakefile +0 -22
  70. data/benchmarks/hash_schemas.rb +0 -55
  71. data/benchmarks/lax_schema.rb +0 -15
  72. data/benchmarks/profile_invalid_input.rb +0 -15
  73. data/benchmarks/profile_lax_schema_valid.rb +0 -16
  74. data/benchmarks/profile_valid_input.rb +0 -15
  75. data/benchmarks/schema_valid_vs_invalid.rb +0 -21
  76. data/benchmarks/setup.rb +0 -17
  77. data/docsite/source/array-with-member.html.md +0 -13
  78. data/docsite/source/built-in-types.html.md +0 -116
  79. data/docsite/source/constraints.html.md +0 -31
  80. data/docsite/source/custom-types.html.md +0 -93
  81. data/docsite/source/default-values.html.md +0 -91
  82. data/docsite/source/enum.html.md +0 -69
  83. data/docsite/source/extensions.html.md +0 -15
  84. data/docsite/source/extensions/maybe.html.md +0 -57
  85. data/docsite/source/extensions/monads.html.md +0 -61
  86. data/docsite/source/getting-started.html.md +0 -57
  87. data/docsite/source/hash-schemas.html.md +0 -169
  88. data/docsite/source/index.html.md +0 -156
  89. data/docsite/source/map.html.md +0 -17
  90. data/docsite/source/optional-values.html.md +0 -35
  91. data/docsite/source/sum.html.md +0 -21
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-2021 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,27 +1,29 @@
1
1
  [gem]: https://rubygems.org/gems/dry-types
2
- [ci]: https://github.com/dry-rb/dry-types/actions?query=workflow%3Aci
3
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-types
4
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-types
2
+ [actions]: https://github.com/dry-rb/dry-types/actions
3
+ [codacy]: https://www.codacy.com/gh/dry-rb/dry-types
5
4
  [chat]: https://dry-rb.zulipchat.com
5
+ [inchpages]: http://inch-ci.org/github/dry-rb/dry-types
6
6
 
7
7
  # dry-types [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/dry-types.svg)][gem]
10
- [![Build Status](https://github.com/dry-rb/dry-types/workflows/ci/badge.svg)][ci]
11
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-types/badges/gpa.svg)][codeclimate]
12
- [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-types/badges/coverage.svg)][codeclimate]
10
+ [![CI Status](https://github.com/dry-rb/dry-types/workflows/ci/badge.svg)][actions]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/f2d71613195f4da993acb9ac9d6ea336)][codacy]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/f2d71613195f4da993acb9ac9d6ea336)][codacy]
13
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-types.svg?branch=master)][inchpages]
14
14
 
15
15
  ## Links
16
16
 
17
- - [Documentation](http://dry-rb.org/gems/dry-types)
17
+ * [User documentation](http://dry-rb.org/gems/dry-types)
18
+ * [API documentation](http://rubydoc.info/gems/dry-types)
18
19
 
19
- ## Development
20
+ ## Supported Ruby versions
20
21
 
21
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake run_specs` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
22
+ This library officially supports the following Ruby versions:
22
23
 
23
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
+ * MRI >= `2.5`
25
+ * jruby >= `9.2`
24
26
 
25
- ## Contributing
27
+ ## License
26
28
 
27
- Bug reports and pull requests are welcome on GitHub at https://github.com/dry-rb/dry-types.
29
+ See `LICENSE` file.
data/dry-types.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # this file is managed by dry-rb/devtools project
2
3
 
3
4
  lib = File.expand_path('lib', __dir__)
4
5
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -6,42 +7,36 @@ require 'dry/types/version'
6
7
 
7
8
  Gem::Specification.new do |spec|
8
9
  spec.name = 'dry-types'
9
- spec.version = Dry::Types::VERSION.dup
10
- spec.authors = ['Piotr Solnica']
11
- spec.email = ['piotr.solnica@gmail.com']
10
+ spec.authors = ["Piotr Solnica"]
11
+ spec.email = ["piotr.solnica@gmail.com"]
12
12
  spec.license = 'MIT'
13
+ spec.version = Dry::Types::VERSION.dup
13
14
 
14
- spec.summary = 'Type system for Ruby supporting coercions, constraints and complex types like structs, value objects, enums etc.'
15
+ spec.summary = "Type system for Ruby supporting coercions, constraints and complex types like structs, value objects, enums etc"
15
16
  spec.description = spec.summary
16
- spec.homepage = 'https://github.com/dry-rb/dry-types'
17
+ spec.homepage = 'https://dry-rb.org/gems/dry-types'
18
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-types.gemspec", "lib/**/*"]
19
+ spec.bindir = 'bin'
20
+ spec.executables = []
21
+ spec.require_paths = ['lib']
17
22
 
18
- # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
- # delete this section to allow pushing this gem to any host.
20
- if spec.respond_to?(:metadata)
21
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
22
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-types/blob/master/CHANGELOG.md'
23
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-types'
24
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-types/issues'
25
- else
26
- raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
27
- end
23
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
+ spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-types/blob/master/CHANGELOG.md'
25
+ spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-types'
26
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-types/issues'
28
27
 
29
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - ['bin/console', 'bin/setup']
30
- spec.bindir = 'exe'
31
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
- spec.require_paths = ['lib']
33
- spec.required_ruby_version = '>= 2.4.0'
28
+ spec.required_ruby_version = ">= 2.5.0"
34
29
 
35
- spec.add_runtime_dependency 'concurrent-ruby', '~> 1.0'
36
- spec.add_runtime_dependency 'dry-container', '~> 0.3'
37
- spec.add_runtime_dependency 'dry-core', '~> 0.4', '>= 0.4.4'
38
- spec.add_runtime_dependency 'dry-equalizer', '~> 0.3'
39
- spec.add_runtime_dependency 'dry-inflector', '~> 0.1', '>= 0.1.2'
40
- spec.add_runtime_dependency 'dry-logic', '~> 1.0', '>= 1.0.2'
30
+ # to update dependencies edit project.yml
31
+ spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
32
+ spec.add_runtime_dependency "dry-container", "~> 0.3"
33
+ spec.add_runtime_dependency "dry-core", "~> 0.5", ">= 0.5"
34
+ spec.add_runtime_dependency "dry-inflector", "~> 0.1", ">= 0.1.2"
35
+ spec.add_runtime_dependency "dry-logic", "~> 1.0", ">= 1.0.2"
41
36
 
42
- spec.add_development_dependency 'bundler'
43
- spec.add_development_dependency 'dry-monads', '~> 0.2'
44
- spec.add_development_dependency 'rake', '~> 11.0'
45
- spec.add_development_dependency 'rspec', '~> 3.3'
46
- spec.add_development_dependency 'yard', '~> 0.9.5'
37
+ spec.add_development_dependency "bundler"
38
+ spec.add_development_dependency "dry-monads", "~> 1.0"
39
+ spec.add_development_dependency "rake"
40
+ spec.add_development_dependency "rspec"
41
+ spec.add_development_dependency "yard"
47
42
  end
data/lib/dry-types.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/types'
3
+ require "dry/types"
data/lib/dry/types.rb CHANGED
@@ -1,27 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bigdecimal'
4
- require 'date'
5
- require 'set'
3
+ require "bigdecimal"
4
+ require "date"
5
+ require "set"
6
6
 
7
- require 'concurrent'
7
+ require "concurrent/map"
8
8
 
9
- require 'dry-container'
10
- require 'dry-equalizer'
11
- require 'dry/core/extensions'
12
- require 'dry/core/constants'
13
- require 'dry/core/class_attributes'
9
+ require "dry/container"
10
+ require "dry/core/extensions"
11
+ require "dry/core/constants"
12
+ require "dry/core/class_attributes"
14
13
 
15
- require 'dry/types/version'
16
- require 'dry/types/container'
17
- require 'dry/types/inflector'
18
- require 'dry/types/type'
19
- require 'dry/types/printable'
20
- require 'dry/types/nominal'
21
- require 'dry/types/constructor'
22
- require 'dry/types/module'
14
+ require "dry/types/version"
15
+ require "dry/types/container"
16
+ require "dry/types/inflector"
17
+ require "dry/types/type"
18
+ require "dry/types/printable"
19
+ require "dry/types/nominal"
20
+ require "dry/types/constructor"
21
+ require "dry/types/module"
23
22
 
24
- require 'dry/types/errors'
23
+ require "dry/types/errors"
25
24
 
26
25
  module Dry
27
26
  # Main library namespace
@@ -37,7 +36,7 @@ module Dry
37
36
 
38
37
  # @see Dry.Types
39
38
  def self.module(*namespaces, default: :nominal, **aliases)
40
- Module.new(container, *namespaces, default: default, **aliases)
39
+ ::Module.new(container, *namespaces, default: default, **aliases)
41
40
  end
42
41
  deprecate_class_method :module, message: <<~DEPRECATION
43
42
  Use Dry.Types() instead. Beware, it exports strict types by default, for old behavior use Dry.Types(default: :nominal). See more options in the changelog
@@ -45,7 +44,7 @@ module Dry
45
44
 
46
45
  # @api private
47
46
  def self.included(*)
48
- raise 'Import Dry.Types, not Dry::Types'
47
+ raise "Import Dry.Types, not Dry::Types"
49
48
  end
50
49
 
51
50
  # Return container with registered built-in type objects
@@ -121,7 +120,7 @@ module Dry
121
120
  #
122
121
  # @return [String]
123
122
  def self.identifier(klass)
124
- Inflector.underscore(klass).tr('/', '.')
123
+ Inflector.underscore(klass).tr("/", ".")
125
124
  end
126
125
 
127
126
  # Cached type map
@@ -130,31 +129,49 @@ module Dry
130
129
  #
131
130
  # @api private
132
131
  def self.type_map
133
- @type_map ||= Concurrent::Map.new
134
- end
135
-
136
- # List of type keys defined in {Dry::Types.container}
137
- #
138
- # @return [String]
139
- #
140
- # @api private
141
- def self.type_keys
142
- container.keys
132
+ @type_map ||= ::Concurrent::Map.new
143
133
  end
144
134
 
145
135
  # @api private
146
136
  def self.const_missing(const)
147
137
  underscored = Inflector.underscore(const)
148
138
 
149
- if container.keys.any? { |key| key.split('.')[0] == underscored }
150
- raise NameError,
151
- 'dry-types does not define constants for default types. '\
139
+ if container.keys.any? { |key| key.split(".")[0] == underscored }
140
+ raise ::NameError,
141
+ "dry-types does not define constants for default types. "\
152
142
  'You can access the predefined types with [], e.g. Dry::Types["integer"] '\
153
- 'or generate a module with types using Dry.Types()'
143
+ "or generate a module with types using Dry.Types()"
154
144
  else
155
145
  super
156
146
  end
157
147
  end
148
+
149
+ # Add a new type builder method. This is a public API for defining custom
150
+ # type constructors
151
+ #
152
+ # @example simple custom type constructor
153
+ # Dry::Types.define_builder(:or_nil) do |type|
154
+ # type.optional.fallback(nil)
155
+ # end
156
+ #
157
+ # Dry::Types["integer"].or_nil.("foo") # => nil
158
+ #
159
+ # @example fallback alias
160
+ # Dry::Types.define_builder(:or) do |type, fallback|
161
+ # type.fallback(fallback)
162
+ # end
163
+ #
164
+ # Dry::Types["integer"].or(100).("foo") # => 100
165
+ #
166
+ # @param [Symbol] method
167
+ # @param [#call] block
168
+ #
169
+ # @api public
170
+ def self.define_builder(method, &block)
171
+ Builder.define_method(method) do |*args|
172
+ block.(self, *args)
173
+ end
174
+ end
158
175
  end
159
176
 
160
177
  # Export registered types as a module with constants
@@ -206,13 +223,11 @@ module Dry
206
223
  #
207
224
  # @api public
208
225
  #
209
- # rubocop:disable Naming/MethodName
210
226
  def self.Types(*namespaces, default: Types::Undefined, **aliases)
211
227
  Types::Module.new(Types.container, *namespaces, default: default, **aliases)
212
228
  end
213
- # rubocop:enable Naming/MethodName
214
229
  end
215
230
 
216
- require 'dry/types/core' # load built-in types
217
- require 'dry/types/extensions'
218
- require 'dry/types/printer'
231
+ require "dry/types/core" # load built-in types
232
+ require "dry/types/extensions"
233
+ require "dry/types/printer"
data/lib/dry/types/any.rb CHANGED
@@ -10,7 +10,7 @@ module Dry
10
10
  # @api public
11
11
  class AnyClass < Nominal
12
12
  def self.name
13
- 'Any'
13
+ "Any"
14
14
  end
15
15
 
16
16
  # @api private
@@ -22,7 +22,7 @@ module Dry
22
22
  #
23
23
  # @api public
24
24
  def name
25
- 'Any'
25
+ "Any"
26
26
  end
27
27
 
28
28
  # @param [Hash] new_options
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/types/array/member'
4
- require 'dry/types/array/constructor'
3
+ require "dry/types/array/member"
4
+ require "dry/types/array/constructor"
5
5
 
6
6
  module Dry
7
7
  module Types
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/types/constructor'
3
+ require "dry/types/constructor"
4
4
 
5
5
  module Dry
6
6
  module Types
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/types/array/constructor'
3
+ require "dry/types/array/constructor"
4
4
 
5
5
  module Dry
6
6
  module Types
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry/core/deprecations'
3
+ require "dry/core/deprecations"
4
4
 
5
5
  module Dry
6
6
  module Types
@@ -42,7 +42,7 @@ module Dry
42
42
  #
43
43
  # @api public
44
44
  def optional
45
- Types['strict.nil'] | self
45
+ Types["nil"] | self
46
46
  end
47
47
 
48
48
  # Turn a type into a constrained type
@@ -59,7 +59,7 @@ module Dry
59
59
  # Turn a type into a type with a default value
60
60
  #
61
61
  # @param [Object] input
62
- # @param [Hash] options
62
+ # @option [Boolean] shared Whether it's safe to share the value across type applications
63
63
  # @param [#call,nil] block
64
64
  #
65
65
  # @raise [ConstraintError]
@@ -69,23 +69,27 @@ module Dry
69
69
  # @api public
70
70
  def default(input = Undefined, options = EMPTY_HASH, &block)
71
71
  unless input.frozen? || options[:shared]
72
- where = Dry::Core::Deprecations::STACK.()
73
- Dry::Core::Deprecations.warn(
72
+ where = Core::Deprecations::STACK.()
73
+ Core::Deprecations.warn(
74
74
  "#{input.inspect} is mutable."\
75
- ' Be careful: types will return the same instance of the default'\
76
- ' value every time. Call `.freeze` when setting the default'\
77
- ' or pass `shared: true` to discard this warning.'\
75
+ " Be careful: types will return the same instance of the default"\
76
+ " value every time. Call `.freeze` when setting the default"\
77
+ " or pass `shared: true` to discard this warning."\
78
78
  "\n#{where}",
79
79
  tag: :'dry-types'
80
80
  )
81
81
  end
82
82
 
83
- value = input.equal?(Undefined) ? block : input
83
+ value = Undefined.default(input, block)
84
+ type = Default[value].new(self, value)
84
85
 
85
- if value.respond_to?(:call) || valid?(value)
86
- Default[value].new(self, value)
86
+ if !type.callable? && !valid?(value)
87
+ raise ConstraintError.new(
88
+ "default value #{value.inspect} violates constraints",
89
+ value
90
+ )
87
91
  else
88
- raise ConstraintError.new("default value #{value.inspect} violates constraints", value)
92
+ type
89
93
  end
90
94
  end
91
95
 
@@ -127,14 +131,62 @@ module Dry
127
131
  #
128
132
  # @api public
129
133
  def constructor(constructor = nil, **options, &block)
130
- constructor_type.new(with(**options), fn: constructor || block)
134
+ constructor_type[with(**options), fn: constructor || block]
135
+ end
136
+ alias_method :append, :constructor
137
+ alias_method :prepend, :constructor
138
+ alias_method :>>, :constructor
139
+ alias_method :<<, :constructor
140
+
141
+ # Use the given value on type mismatch
142
+ #
143
+ # @param [Object] value
144
+ # @option [Boolean] shared Whether it's safe to share the value across type applications
145
+ # @param [#call,nil] fallback
146
+ #
147
+ # @return [Constructor]
148
+ #
149
+ # @api public
150
+ def fallback(value = Undefined, shared: false, &_fallback)
151
+ if Undefined.equal?(value) && !block_given?
152
+ raise ::ArgumentError, "fallback value or a block must be given"
153
+ end
154
+
155
+ if !block_given? && !valid?(value)
156
+ raise ConstraintError.new(
157
+ "fallback value #{value.inspect} violates constraints",
158
+ value
159
+ )
160
+ end
161
+
162
+ unless value.frozen? || shared
163
+ where = Core::Deprecations::STACK.()
164
+ Core::Deprecations.warn(
165
+ "#{value.inspect} is mutable."\
166
+ " Be careful: types will return the same instance of the fallback"\
167
+ " value every time. Call `.freeze` when setting the fallback"\
168
+ " or pass `shared: true` to discard this warning."\
169
+ "\n#{where}",
170
+ tag: :'dry-types'
171
+ )
172
+ end
173
+
174
+ constructor do |input, type, &_block|
175
+ type.(input) do |output = input|
176
+ if block_given?
177
+ yield(output)
178
+ else
179
+ value
180
+ end
181
+ end
182
+ end
131
183
  end
132
184
  end
133
185
  end
134
186
  end
135
187
 
136
- require 'dry/types/default'
137
- require 'dry/types/constrained'
138
- require 'dry/types/enum'
139
- require 'dry/types/lax'
140
- require 'dry/types/sum'
188
+ require "dry/types/default"
189
+ require "dry/types/constrained"
190
+ require "dry/types/enum"
191
+ require "dry/types/lax"
192
+ require "dry/types/sum"