class Axiom::Algebra::Restriction

Restrict the tuples to those that match a predicate

Constants

TAUTOLOGY

Attributes

predicate[R]

The predicate for the relation

@return [Function, call]

@api private

Public Class Methods

new(operand, predicate) click to toggle source

Initialize a Restriction

@param [Relation] operand

the relation to restrict

@param [Function, call] predicate

the function to restrict the tuples with

@return [undefined]

@api private

Calls superclass method Axiom::Relation::Operation::Unary::new
# File lib/axiom/algebra/restriction.rb, line 30
def initialize(operand, predicate)
  super(operand)
  @predicate = predicate
end

Public Instance Methods

delete(other) click to toggle source

Delete a relation from the Restriction

The tuples must match the predicate to be deleted.

@example

new_relation = restriction.delete(other)

@param [Relation] other

@return [Restriction]

@api public

# File lib/axiom/algebra/restriction.rb, line 86
def delete(other)
  other = coerce(other)
  operand.delete(other.restrict(predicate)).restrict(predicate)
end
each() { |tuple| ... } click to toggle source

Iterate over each tuple in the set

@example

restriction = Restriction.new(operand, predicate)
restriction.each { |tuple| ... }

@yield [tuple]

@yieldparam [Tuple] tuple

each tuple in the set

@return [self]

@api public

# File lib/axiom/algebra/restriction.rb, line 49
def each
  return to_enum unless block_given?
  operand.each do |tuple|
    yield tuple if Function.extract_value(predicate, tuple).equal?(true)
  end
  self
end
insert(other) click to toggle source

Insert a relation into the Restriction

The tuples must match the predicate to be inserted.

@example

new_relation = restriction.insert(other)

@param [Relation] other

@return [Restriction]

@api public

# File lib/axiom/algebra/restriction.rb, line 69
def insert(other)
  other = coerce(other)
  operand.insert(other.restrict(predicate)).restrict(predicate)
end