Sha256: 0f8730cfe968645b1c7970c68d19b13c7e154f5f49e6fe6bcc1dd27d56bb7c42
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
require 'transproc/composite' module Transproc # Transformation proc wrapper allowing composition of multiple procs into # a data-transformation pipeline. # # This is used by Transproc to wrap registered methods. # # @api private class Function # Wrapped proc or another composite function # # @return [Proc,Composed] # # @api private attr_reader :fn # Additional arguments that will be passed to the wrapped proc # # @return [Array] # # @api private attr_reader :args # @!attribute [r] name # # @return [<type] The name of the function # # @api public attr_reader :name # @api private def initialize(fn, options = {}) @fn = fn @args = options.fetch(:args, []) @name = options.fetch(:name, fn) end # Call the wrapped proc # # @param [Object] value The input value # # @alias [] # # @api public def call(*value) fn[*value, *args] rescue => e raise MalformedInputError.new(@name, value, e) end alias_method :[], :call # Compose this function with another function or a proc # # @param [Proc,Function] # # @return [Composite] # # @alias :>> # # @api public def compose(other) Composite.new(self, other) end alias_method :+, :compose alias_method :>>, :compose # Return a new fn with curried args # # @return [Function] # # @api private def with(*args) self.class.new(fn, name: name, args: args) end # @api public def ==(other) return false unless other.instance_of?(self.class) [fn, name, args] == [other.fn, other.name, other.args] end alias_method :eql?, :== # Return a simple AST representation of this function # # @return [Array] # # @api public def to_ast [name, args] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
transproc-0.3.0 | lib/transproc/function.rb |