Sha256: f15024c02aaf31c4442b1fd33905a2c6ae2602ba2ad0ee0c1cc2b3251490cd1c

Contents?: true

Size: 908 Bytes

Versions: 2

Compression:

Stored size: 908 Bytes

Contents

# frozen_string_literal: true

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.call(left.call(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

2 entries across 2 versions & 1 rubygems

Version Path
transproc-1.1.1 lib/transproc/composite.rb
transproc-1.1.0 lib/transproc/composite.rb