class Dry::Types::Constructor::Function
@api private
Function is used internally by Constructor types
def self.[](fn)
-
(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)
-
(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)
-
(Function)
-
def <<(other) f = Function[other] Function[-> x, &b { self.(f.(x, &b), &b) }] end
def >>(other)
-
(Function)
-
def >>(other) f = Function[other] Function[-> x, &b { f.(self.(x, &b), &b) }] end
def arity = 1
-
(Integer)
-
def arity = 1
def call(input, &) = @fn.(input, &)
-
(Object)
-
def call(input, &) = @fn.(input, &)
def initialize(fn)
def initialize(fn) @fn = fn end
def to_ast
-
(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)