Class: Bmg::Operator::Minus

Inherits:
Object
  • Object
show all
Includes:
Nary
Defined in:
lib/bmg/operator/minus.rb

Overview

Minus operator.

Returns all tuples which are in the left operand but not in the right operand.

This implementation is actually a NAry-Minus, since it handles an arbitrary number of operands.

Instance Attribute Summary

Attributes included from Bmg::Operator

#type

Instance Method Summary collapse

Methods included from Nary

#bind

Methods included from Bmg::Operator

#inspect, #to_s

Methods included from Relation

#_count, #bind, #count, #debug, #delete, empty, #empty?, #insert, new, #one, #one_or_nil, #to_csv, #to_json, #to_xlsx, #type, #update, #visit, #with_type, #with_type_attrlist, #with_typecheck, #without_typecheck, #y_by_x, #ys_by_x

Methods included from Algebra

#allbut, #autosummarize, #autowrap, #constants, #extend, #group, #image, #join, #left_join, #matching, #materialize, #minus, #not_matching, #page, #project, #rename, #restrict, #spied, #summarize, #transform, #ungroup, #union, #unspied, #unwrap

Methods included from Algebra::Shortcuts

#cross_product, #exclude, #image, #images, #join, #left_join, #matching, #not_matching, #prefix, #rxmatch, #suffix, #ungroup, #unwrap, #where

Constructor Details

#initialize(type, operands) ⇒ Minus

Returns a new instance of Minus.



15
16
17
18
# File 'lib/bmg/operator/minus.rb', line 15

def initialize(type, operands)
  @type = type
  @operands = operands
end

Instance Method Details

#each(&bl) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/bmg/operator/minus.rb', line 22

def each(&bl)
  return to_enum unless block_given?
  initial = operands[0].to_set
  tuples = operands.drop(1).inject(initial) do |agg, op|
    agg - op.to_set
  end
  tuples.each(&bl)
end

#to_astObject



31
32
33
# File 'lib/bmg/operator/minus.rb', line 31

def to_ast
  [ :minus ] + operands.map(&:to_ast)
end