Class: Dry::Types::Intersection

Inherits:
Object
  • Object
show all
Includes:
Composition
Defined in:
lib/dry/types/intersection.rb

Overview

Intersection type

Instance Attribute Summary

Attributes included from Composition

#left, #right

Attributes included from Options

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Composition

#constrained?, #default?, #failure, included, #initialize, #name, #optional?, #success, #to_ast, #to_proc

Methods included from Printable

#to_s

Methods included from Meta

#initialize, #meta, #pristine, #with

Methods included from Options

#initialize, #with

Methods included from Builder

#&, #>, #constrained, #constrained_type, #constructor, #constructor_type, #default, #enum, #fallback, #lax, #maybe, #optional, #|

Methods included from Type

#call, #valid?

Class Method Details

.operatorObject

[View source]

15
# File 'lib/dry/types/intersection.rb', line 15

def self.operator = :&

Instance Method Details

#call_safe(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.

Parameters:

  • input (Object)

Returns:

  • (Object)
[View source]

31
# File 'lib/dry/types/intersection.rb', line 31

def call_safe(input, &) = try_sides(input, &).input

#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.

Parameters:

  • input (Object)

Returns:

  • (Object)
[View source]

22
23
24
# File 'lib/dry/types/intersection.rb', line 22

def call_unsafe(input)
  merge_results(left.call_unsafe(input), right.call_unsafe(input))
end

#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.

Parameters:

  • value (Object)

Returns:

  • (Boolean)
[View source]

51
52
53
# File 'lib/dry/types/intersection.rb', line 51

def primitive?(value)
  left.primitive?(value) && right.primitive?(value)
end

#try(input) ⇒ Object

Parameters:

  • input (Object)
[View source]

36
37
38
39
40
41
42
43
44
# File 'lib/dry/types/intersection.rb', line 36

def try(input)
  try_sides(input) do |failure|
    if block_given?
      yield(failure)
    else
      failure
    end
  end
end