In [4]:
from fito import Operation, SpecField, PrimitiveField
class Numeric(Operation):
def __add__(self, other):
return AddOperation(self, other)
class Number(Numeric):
n = PrimitiveField(0)
def apply(self, runner):
return self.n
def __repr__(self):
return str(self.n)
class AddOperation(Numeric):
left = SpecField(0)
right = SpecField(1)
def apply(self, runner):
return runner.execute(self.left) + runner.execute(self.right)
def __repr__(self):
return "{} + {}".format(self.left, self.right)
In [9]:
from fito.operation_runner import OperationRunner
# Data store with execution caching
runner = OperationRunner(execute_cache_size=10)
# operation runner without execution caching
# Try uncommenting this line to see the behaviour of the following cells
# data_store = OperationRunner()
op = Number(1) + Number(2)
print op
print op + Number(3)
In [10]:
print
print "Operation: {}".format(op)
print
print "Result: {}".format(runner.execute(op))
In [12]:
print "Result: {}".format(data_store.execute(op + op))