Sha256: e22d1218aada7fa893159d0824cb89f005212e7b3754126a63db635318af37b5

Contents?: true

Size: 1.01 KB

Versions: 17

Compression:

Stored size: 1.01 KB

Contents

module Bmg
  module Operator
    #
    # Restrict operator.
    #
    # Filters operand's tuples to those that meet the predicate received
    # at construction.
    #
    class Restrict
      include Operator::Unary

      def initialize(type, operand, predicate)
        @type = type
        @operand = operand
        @predicate = predicate
      end

    protected

      attr_reader :predicate

    public

      def bind(binding)
        Restrict.new(type, operand.bind(binding), predicate.bind(binding))
      end

      def each
        return to_enum unless block_given?
        @operand.each do |tuple|
          yield(tuple) if @predicate.evaluate(tuple)
        end
      end

      def to_ast
        [ :restrict, operand.to_ast, predicate.sexpr ]
      end

    protected

      def _restrict(type, predicate)
        Restrict.new(type, @operand, @predicate & predicate)
      end

    protected ### inspect

      def args
        [ predicate ]
      end

    end # class Restrict
  end # module Operator
end # module Bmg

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
bmg-0.19.3 lib/bmg/operator/restrict.rb
bmg-0.19.2 lib/bmg/operator/restrict.rb
bmg-0.19.1 lib/bmg/operator/restrict.rb
bmg-0.19.0 lib/bmg/operator/restrict.rb
bmg-0.18.15 lib/bmg/operator/restrict.rb
bmg-0.18.14 lib/bmg/operator/restrict.rb
bmg-0.18.13 lib/bmg/operator/restrict.rb
bmg-0.18.12 lib/bmg/operator/restrict.rb
bmg-0.18.11 lib/bmg/operator/restrict.rb
bmg-0.18.10 lib/bmg/operator/restrict.rb
bmg-0.18.9 lib/bmg/operator/restrict.rb
bmg-0.18.8 lib/bmg/operator/restrict.rb
bmg-0.18.7 lib/bmg/operator/restrict.rb
bmg-0.18.6 lib/bmg/operator/restrict.rb
bmg-0.18.5 lib/bmg/operator/restrict.rb
bmg-0.18.4 lib/bmg/operator/restrict.rb
bmg-0.18.3 lib/bmg/operator/restrict.rb