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.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) proc = other.is_a?(::Proc) ? other : other.fn Function[@fn << proc] end
def <<(other)
-
(Function)
-
def <<(other) proc = other.is_a?(::Proc) ? other : other.fn Function[-> x { @fn[proc[x]] }] end
def >>(other)
-
(Function)
-
def >>(other) proc = other.is_a?(::Proc) ? other : other.fn Function[@fn >> proc] end
def >>(other)
-
(Function)
-
def >>(other) proc = other.is_a?(::Proc) ? other : other.fn Function[-> x { proc[@fn[x]] }] end
def call(input, &block)
-
(Object)
-
def call(input, &block) @fn.(input, &block) end
def initialize(fn)
def initialize(fn) @fn = fn end
def to_ast
-
(Array)
-
def to_ast if fn.is_a?(::Proc) [:id, Dry::Types::FnContainer.register(fn)] else [:callable, fn] end end