Class: Bmg::Operator::Restrict
- Inherits:
-
Object
- Object
- Bmg::Operator::Restrict
- Includes:
- Unary
- Defined in:
- lib/bmg/operator/restrict.rb
Overview
Restrict operator.
Filters operand’s tuples to those that meet the predicate received at construction.
Instance Attribute Summary
Attributes included from Unary
Attributes included from Bmg::Operator
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(type, operand, predicate) ⇒ Restrict
constructor
A new instance of Restrict.
- #to_ast ⇒ Object
Methods included from Unary
Methods included from Bmg::Operator
Methods included from Relation
#debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_json, #update, #visit, #with_typecheck, #without_typecheck, #ys_by_x
Methods included from Algebra
#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #matching, #not_matching, #page, #project, #rename, #restrict, #spied, #union, #unspied
Methods included from Algebra::Shortcuts
Constructor Details
#initialize(type, operand, predicate) ⇒ Restrict
Returns a new instance of Restrict.
12 13 14 15 16 |
# File 'lib/bmg/operator/restrict.rb', line 12 def initialize(type, operand, predicate) @type = type @operand = operand @predicate = predicate end |
Instance Method Details
#each ⇒ Object
24 25 26 27 28 |
# File 'lib/bmg/operator/restrict.rb', line 24 def each @operand.each do |tuple| yield(tuple) if @predicate.evaluate(tuple) end end |
#to_ast ⇒ Object
30 31 32 |
# File 'lib/bmg/operator/restrict.rb', line 30 def to_ast [ :restrict, operand.to_ast, predicate.sexpr ] end |