class Transproc::Function
Transformation proc wrapper allowing composition of multiple procs into a data-transformation pipeline.
This is used by Transproc
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/transproc/function.rb, line 35 def initialize(fn, options = {}) @fn = fn @args = options.fetch(:args, []) @name = options.fetch(:name, fn) end
Public Instance Methods
@api public
# File lib/transproc/function.rb, line 78 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/transproc/function.rb, line 48 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/transproc/function.rb, line 62 def compose(other) Composite.new(self, other) end
Return a simple AST representation of this function
@return [Array]
@api public
# File lib/transproc/function.rb, line 89 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/transproc/function.rb, line 98 def to_proc if args.size > 0 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/transproc/function.rb, line 73 def with(*args) self.class.new(fn, name: name, args: args) end