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.respond_to?(:arity) && fn.arity.equal?(2)
    Wrapper.new(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)
  f = Function[other]
  Function[-> x, &b { self.(f.(x, &b), &b) }]
end

def >>(other)

Returns:
  • (Function) -
def >>(other)
  f = Function[other]
  Function[-> x, &b { f.(self.(x, &b), &b) }]
end

def arity = 1

Returns:
  • (Integer) -
def arity = 1

def call(input, &) = @fn.(input, &)

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

def initialize(fn)

def initialize(fn)
  @fn = fn
end

def to_ast

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

def wrapper? = arity.equal?(2)

def wrapper? = arity.equal?(2)