class Dry::Transformer::Function
Transformation proc wrapper allowing composition of multiple procs into a data-transformation pipeline.
This is used by Dry::Transformer
to wrap registered methods.
@api private
Attributes
Additional arguments that will be passed to the wrapped proc
@return [Array]
@api private
Wrapped proc or another composite function
@return [Proc,Composed]
@api private
@!attribute [r] name
@return [<type] The name of the function
@api public
Public Class Methods
@api private
# File lib/dry/transformer/function.rb, line 36 def initialize(fn, options = {}) @fn = fn @args = options.fetch(:args, []) @name = options.fetch(:name, fn) end
Public Instance Methods
@api public
# File lib/dry/transformer/function.rb, line 79 def ==(other) return false unless other.instance_of?(self.class) [fn, name, args] == [other.fn, other.name, other.args] end
Call the wrapped proc
@param [Object] value The input value
@alias []
@api public
# File lib/dry/transformer/function.rb, line 49 def call(*value) fn.call(*value, *args) end
Compose this function with another function or a proc
@param [Proc,Function]
@return [Composite]
@alias :>>
@api public
# File lib/dry/transformer/function.rb, line 63 def compose(other) Composite.new(self, other) end
Return a simple AST representation of this function
@return [Array]
@api public
# File lib/dry/transformer/function.rb, line 91 def to_ast args_ast = args.map { |arg| arg.respond_to?(:to_ast) ? arg.to_ast : arg } [name, args_ast] end
Converts a transproc to a simple proc
@return [Proc]
# File lib/dry/transformer/function.rb, line 100 def to_proc if !args.empty? proc { |*value| fn.call(*value, *args) } else fn.to_proc end end
Return a new fn with curried args
@return [Function]
@api private
# File lib/dry/transformer/function.rb, line 74 def with(*args) self.class.new(fn, name: name, args: args) end