Sha256: 090739124aebb6e2032aaabf3bee43be6937128d62d776c035c89ef7c28e142d

Contents?: true

Size: 867 Bytes

Versions: 6

Compression:

Stored size: 867 Bytes

Contents

module Transproc
  # Composition of two functions
  #
  # @api private
  class Composite
    # @return [Proc]
    #
    # @api private
    attr_reader :left

    # @return [Proc]
    #
    # @api private
    attr_reader :right

    # @api private
    def initialize(left, right)
      @left = left
      @right = right
    end

    # Call right side with the result from the left side
    #
    # @param [Object] value The input value
    #
    # @return [Object]
    #
    # @api public
    def call(value)
      right[left[value]]
    end
    alias_method :[], :call

    # @see Function#compose
    #
    # @api public
    def compose(other)
      self.class.new(self, other)
    end
    alias_method :+, :compose
    alias_method :>>, :compose

    # @see Function#to_ast
    #
    # @api public
    def to_ast
      left.to_ast << right.to_ast
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
transproc-0.3.1 lib/transproc/composite.rb
transproc-0.3.0 lib/transproc/composite.rb
transproc-0.2.4 lib/transproc/composite.rb
transproc-0.2.3 lib/transproc/composite.rb
transproc-0.2.2 lib/transproc/composite.rb
transproc-0.2.1 lib/transproc/composite.rb