6.12.5.1.1. Composable Function

First, we need to be able to compose functions. The function class accepts a list of functions as arguments, saves the list, and calls the functions from left to right when required, passing the single allowed argument to the first function, and the result of that along the chain. The result returned is a traditional value, as is the argument.
Start python section to interscript/felix/model/funcat.py[1 /8 ] Next Last
     1: #line 21 "felix_func.ipk"
     2: from interscript.felix.model.basecat import category
     3: 
     4: class function:
     5:   def __init__(self, *args):
     6:     self.funcs = args
     7:     self.normalise()
     8: 
     9:   def __call__(self, arg):
    10:     for f in self.funcs:
    11:       #print 'calling',f,'arg',arg
    12:       arg = f(arg)
    13:     return arg
    14: 
    15:   def __and__(self,func):
    16:     return apply(function,self.funcs+func.funcs).normalise()
    17: 
    18:   def __mul__(self, func):
    19:     return function(function_product(self,func))
    20: 
    21:   def __add__(self, func):
    22:     return function(function_sum(self,func))
    23: 
    24:   def normalise(self):
    25:     if self.funcs:
    26:       first = self.funcs[0]
    27:       if isinstance(first, constant):
    28:         self.funcs = (constant(self(None)),)
    29:     return self
    30: 
End python section to interscript/felix/model/funcat.py[1]