Skip to content
Snippets Groups Projects

Resolve "Define arithmetics and transformations on containers"

Files
3
@@ -240,6 +240,31 @@ class ForEachSC(ForEachObject):
"""Return a ForEachMOSA instance by sharing the spacecraft values on both MOSAs."""
return ForEachMOSA(lambda mosa: self[ForEachMOSA.sc(mosa)])
def __add__(self, other):
if isinstance(other, ForEachMOSA):
return self.for_each_mosa() + other
return super().__add__(other)
def __sub__(self, other):
if isinstance(other, ForEachMOSA):
return self.for_each_mosa() - other
return super().__sub__(other)
def __mul__(self, other):
if isinstance(other, ForEachMOSA):
return self.for_each_mosa() * other
return super().__mul__(other)
def __floordiv__(self, other):
if isinstance(other, ForEachMOSA):
return self.for_each_mosa() // other
return super().__floordiv__(other)
def __truediv__(self, other):
if isinstance(other, ForEachMOSA):
return self.for_each_mosa() / other
return super().__truediv__(other)
class ForEachMOSA(ForEachObject):
"""Represents a dictionary of values for each moveable optical subassembly (MOSA)."""
@@ -283,3 +308,28 @@ class ForEachMOSA(ForEachObject):
def adjacent(self):
"""Return a ForEachMOSA instance for adjacent MOSAs."""
return ForEachMOSA(lambda mosa: self[ForEachMOSA.adjacent_mosa(mosa)])
def __add__(self, other):
if isinstance(other, ForEachSC):
return self + other.for_each_mosa()
return super().__add__(other)
def __sub__(self, other):
if isinstance(other, ForEachSC):
return self - other.for_each_mosa()
return super().__sub__(other)
def __mul__(self, other):
if isinstance(other, ForEachSC):
return self * other.for_each_mosa()
return super().__mul__(other)
def __floordiv__(self, other):
if isinstance(other, ForEachSC):
return self // other.for_each_mosa()
return super().__floordiv__(other)
def __truediv__(self, other):
if isinstance(other, ForEachSC):
return self / other.for_each_mosa()
return super().__truediv__(other)
Loading