Sha256: c102b250370983fb6b9caa24e2217a8d9fe198db4794d2958c3298d5a5404167

Contents?: true

Size: 511 Bytes

Versions: 3

Compression:

Stored size: 511 Bytes

Contents

module Transproc
  module Composer

    class Factory
      attr_reader :fns, :default

      def initialize(default = nil)
        @fns = []
        @default = default
      end

      def <<(other)
        fns.concat(Array(other).compact)
        self
      end

      def to_fn
        fns.reduce(:+) || default
      end
    end

    def t(*args)
      Transproc(*args)
    end

    def compose(default = nil)
      factory = Factory.new(default)
      yield(factory)
      factory.to_fn
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
transproc-0.1.2 lib/transproc/composer.rb
transproc-0.1.1 lib/transproc/composer.rb
transproc-0.1.0 lib/transproc/composer.rb