Class: Dry::Types::Implication
- Inherits:
-
Object
- Object
- Dry::Types::Implication
- Includes:
- Composition
- Defined in:
- lib/dry/types/implication.rb
Overview
Implication type
Instance Attribute Summary collapse
- #left ⇒ Type included from Composition readonly
- #options ⇒ Hash included from Options readonly private
- #right ⇒ Type included from Composition readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#&(other) ⇒ Intersection, Intersection::Constrained
included
from Builder
private
Compose two types into an Intersection type.
-
#>(other) ⇒ Implication, Implication::Constrained
included
from Builder
private
Compose two types into an Implication type.
-
#call(input = Undefined, &block) ⇒ Object
(also: #[])
included
from Type
Apply type to a value.
- #call_safe(input, &block) ⇒ Object private
- #call_unsafe(input) ⇒ Object private
-
#constrained ⇒ Constrained
included
from Builder
Turn a type into a constrained type.
- #constrained? ⇒ false included from Composition
- #constrained_type ⇒ Class included from Builder private
-
#constructor(constructor = nil, **options, &block) ⇒ Constructor
(also: #append, #prepend, #>>, #<<)
included
from Builder
Define a constructor for the type.
- #constructor_type ⇒ Class included from Builder private
-
#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default
included
from Builder
Turn a type into a type with a default value.
- #default? ⇒ false included from Composition
-
#enum(*values) ⇒ Enum
included
from Builder
Define an enum on top of the existing type.
- #failure(input, _error = nil) ⇒ Object included from Composition private
-
#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor
included
from Builder
Use the given value on type mismatch.
- #initialize(left, right, **options) ⇒ Object included from Composition private
-
#lax ⇒ Lax
included
from Builder
Turn a type into a lax type that will rescue from type-errors and return the original input.
-
#maybe ⇒ Maybe
included
from Builder
Turn a type into a maybe type.
- #meta(data = Undefined) ⇒ Object included from Meta
- #name ⇒ String included from Composition
-
#optional ⇒ Sum
included
from Builder
Turn a type into an optional type.
- #optional? ⇒ Boolean included from Composition
- #primitive?(value) ⇒ Boolean private
-
#pristine ⇒ Dry::Types::Type
included
from Meta
Resets meta.
- #success(input) ⇒ Object included from Composition private
- #to_ast(meta: true) ⇒ Object included from Composition
-
#to_proc ⇒ Proc
included
from Composition
Wrap the type with a proc.
- #to_s ⇒ String (also: #inspect) included from Printable private
- #try(input) ⇒ Object
-
#valid?(input = Undefined) ⇒ Boolean
(also: #===)
included
from Type
private
Whether a value is a valid member of the type.
- #with(**options) ⇒ Type included from Meta
-
#|(other) ⇒ Sum, Sum::Constrained
included
from Builder
private
Compose two types into a Sum type.
Instance Attribute Details
#left ⇒ Type (readonly) Originally defined in module Composition
#options ⇒ Hash (readonly) Originally defined in module Options
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#right ⇒ Type (readonly) Originally defined in module Composition
Class Method Details
.operator ⇒ Object
11 12 13 |
# File 'lib/dry/types/implication.rb', line 11 def self.operator :> end |
Instance Method Details
#&(other) ⇒ Intersection, Intersection::Constrained Originally defined in module Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compose two types into an Intersection type
#>(other) ⇒ Implication, Implication::Constrained Originally defined in module Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compose two types into an Implication type
#call(input = Undefined) ⇒ Object #call(input = Undefined) {|output| ... } ⇒ Object Also known as: [] Originally defined in module Type
Apply type to a value
#call_safe(input, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 38 39 |
# File 'lib/dry/types/implication.rb', line 33 def call_safe(input, &block) if left.try(input).success? right.call_safe(input, &block) else input end end |
#call_unsafe(input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 |
# File 'lib/dry/types/implication.rb', line 20 def call_unsafe(input) if left.try(input).success? right.call_unsafe(input) else input end end |
#constrained ⇒ Constrained Originally defined in module Builder
Turn a type into a constrained type
#constrained? ⇒ false Originally defined in module Composition
#constrained_type ⇒ Class Originally defined in module Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#constructor(constructor = nil, **options, &block) ⇒ Constructor Also known as: append, prepend, >>, << Originally defined in module Builder
Define a constructor for the type
#constructor_type ⇒ Class Originally defined in module Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#default(input = Undefined, options = EMPTY_HASH, &block) ⇒ Default Originally defined in module Builder
Turn a type into a type with a default value
#default? ⇒ false Originally defined in module Composition
#enum(*values) ⇒ Enum Originally defined in module Builder
Define an enum on top of the existing type
#failure(input, _error = nil) ⇒ Object Originally defined in module Composition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#fallback(value = Undefined, shared: false, &_fallback) ⇒ Constructor Originally defined in module Builder
Use the given value on type mismatch
#initialize(left, right, **options) ⇒ Object Originally defined in module Composition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#lax ⇒ Lax Originally defined in module Builder
Turn a type into a lax type that will rescue from type-errors and return the original input
#name ⇒ String Originally defined in module Composition
#optional? ⇒ Boolean Originally defined in module Composition
#primitive?(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
57 58 59 60 61 62 63 |
# File 'lib/dry/types/implication.rb', line 57 def primitive?(value) if left.primitive?(value) right.primitive?(value) else true end end |
#pristine ⇒ Dry::Types::Type Originally defined in module Meta
Resets meta
#success(input) ⇒ Object Originally defined in module Composition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#to_ast(meta: true) ⇒ Object Originally defined in module Composition
#to_proc ⇒ Proc Originally defined in module Composition
Wrap the type with a proc
#to_s ⇒ String Also known as: inspect Originally defined in module Printable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
#try(input) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/dry/types/implication.rb', line 44 def try(input) if left.try(input).success? right.try(input) else Result::Success.new(input) end end |
#valid?(input = Undefined) ⇒ Boolean Also known as: === Originally defined in module Type
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether a value is a valid member of the type
#|(other) ⇒ Sum, Sum::Constrained Originally defined in module Builder
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compose two types into a Sum type