module Dry::Types::Composition

def self.included(base)

def self.included(base)
  composition_name = Inflector.demodulize(base)
  ast_type = Inflector.underscore(composition_name).to_sym
  base.define_singleton_method(:ast_type) { ast_type }
  base.define_singleton_method(:composition_name) { composition_name }
  base.const_set("Constrained", Class.new(base) { include Constrained })
end

def call_safe(input, &block)

Other tags:
    Api: - private

Returns:
  • (Object) -

Parameters:
  • input (Object) --
def call_safe(input, &block)
  raise NotImplementedError
end

def call_unsafe(input)

Other tags:
    Api: - private

Returns:
  • (Object) -

Parameters:
  • input (Object) --
def call_unsafe(input)
  raise NotImplementedError
end

def constrained?

Other tags:
    Api: - public

Returns:
  • (false) -
def constrained?
  false
end

def default?

Other tags:
    Api: - public

Returns:
  • (false) -
def default?
  false
end

def failure(input, _error = nil)

Other tags:
    Api: - private
def failure(input, _error = nil)
  result = try(input)
  if result.failure?
    result
  else
    raise ArgumentError, "Invalid failure value '#{input}' for #{inspect}"
  end
end

def initialize(left, right, **options)

Other tags:
    Api: - private

Parameters:
  • options (Hash) --
  • right (Type) --
  • left (Type) --
def initialize(left, right, **options)
  super
  @left, @right = left, right
  freeze
end

def name

Other tags:
    Api: - public

Returns:
  • (String) -
def name
  [left, right].map(&:name).join(" #{self.class.operator} ")
end

def optional?

Other tags:
    Api: - public

Returns:
  • (Boolean) -
def optional?
  false
end

def primitive?(value)

Other tags:
    Api: - private

Returns:
  • (Boolean) -

Parameters:
  • value (Object) --
def primitive?(value)
  raise NotImplementedError
end

def success(input)

Other tags:
    Api: - private
def success(input)
  result = try(input)
  if result.success?
    result
  else
    raise ArgumentError, "Invalid success value '#{input}' for #{inspect}"
  end
end

def to_ast(meta: true)

Other tags:
    Api: - public

Other tags:
    See: Nominal#to_ast -
def to_ast(meta: true)
  [self.class.ast_type,
   [left.to_ast(meta: meta), right.to_ast(meta: meta), meta ? self.meta : EMPTY_HASH]]
end

def to_proc

Other tags:
    Api: - public

Returns:
  • (Proc) -
def to_proc
  proc { |value| self.(value) }
end

def try(input)

Other tags:
    Api: - public

Parameters:
  • input (Object) --
def try(input)
  raise NotImplementedError
end