class Dry::Types::Constructor::Function

@api private
Function is used internally by Constructor types

def self.[](fn)

Returns:
  • (Function) -

Parameters:
  • fn (#call) --
def self.[](fn)
  raise ArgumentError, 'Missing constructor block' if fn.nil?
  if fn.is_a?(Function)
    fn
  elsif fn.is_a?(::Method)
    MethodCall[fn, yields_block?(fn)]
  elsif yields_block?(fn)
    new(fn)
  else
    Safe.new(fn)
  end
end

def self.yields_block?(fn)

Returns:
  • (Boolean) -
def self.yields_block?(fn)
  *, (last_arg,) =
    if fn.respond_to?(:parameters)
      fn.parameters
    else
      fn.method(:call).parameters
    end
  last_arg.equal?(:block)
end

def <<(other)

Returns:
  • (Function) -
def <<(other)
  proc = other.is_a?(::Proc) ? other : other.fn
  Function[@fn << proc]
end

def <<(other)

Returns:
  • (Function) -
def <<(other)
  proc = other.is_a?(::Proc) ? other : other.fn
  Function[-> x { @fn[proc[x]] }]
end

def >>(other)

Returns:
  • (Function) -
def >>(other)
  proc = other.is_a?(::Proc) ? other : other.fn
  Function[@fn >> proc]
end

def >>(other)

Returns:
  • (Function) -
def >>(other)
  proc = other.is_a?(::Proc) ? other : other.fn
  Function[-> x { proc[@fn[x]] }]
end

def call(input, &block)

Returns:
  • (Object) -
def call(input, &block)
  @fn.(input, &block)
end

def initialize(fn)

def initialize(fn)
  @fn = fn
end

def to_ast

Returns:
  • (Array) -
def to_ast
  if fn.is_a?(::Proc)
    [:id, Dry::Types::FnContainer.register(fn)]
  else
    [:callable, fn]
  end
end