Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
set: Implement __or__ of set
  • Loading branch information
DoDaek committed Sep 17, 2019
commit bbad46092aeb8c6c6cf3d51ceb6f4643f9550040
14 changes: 14 additions & 0 deletions py/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ func (s *Set) M__and__(other Object) (Object, error) {
return ret, nil
}

func (s *Set) M__or__(other Object) (Object, error) {
ret := s
Comment thread
corona10 marked this conversation as resolved.
Outdated
b, ok := other.(*Set)
if !ok {
return nil, ExceptionNewf(TypeError, "unsupported operand type(s) for &: '%s' and '%s'", s.Type().Name, other.Type().Name)
}
for i := range b.items {
if _, ok := s.items[i]; !ok {
ret.items[i] = SetValue{}
}
}
return ret, nil
}

// Check interface is satisfied
var _ I__len__ = (*Set)(nil)
var _ I__bool__ = (*Set)(nil)
Expand Down
17 changes: 17 additions & 0 deletions py/tests/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,21 @@
assert 2 in d
assert 3 in d

doc="__or__"
a = {1, 2, 3}
b = {2, 3, 4, 5}
c = a.__or__(b)
assert 1 in c
assert 2 in c
assert 3 in c
assert 4 in c
assert 5 in c

d = a | b
assert 1 in c
assert 2 in c
assert 3 in c
assert 4 in c
assert 5 in c

doc="finished"