Ejemplo n.º 1
0
 def insert_helper(node):
     if val < node[2]:
         if node[0] is not None:
             return (node[0].then(insert_helper), node[1], node[2])
         else:
             return (taskloaf.ready((None,None,val)), node[1], node[2])
     else:
         if node[1] is not None:
             return (node[0], node[1].then(insert_helper), node[2])
         else:
             return (node[0], taskloaf.ready((None,None,val)), node[2])
Ejemplo n.º 2
0
 def print_helper(t, indent):
     out = taskloaf.ready('    ' * indent + str(t[2]) + '\n')
     if t[0] != None:
         out = concat(out, t[0].then(lambda t: print_helper(t, indent + 1)).unwrap())
     if t[1] != None:
         out = concat(out, t[1].then(lambda t: print_helper(t, indent + 1)).unwrap())
     return out
Ejemplo n.º 3
0
 def fib(i):
     if i < 3:
         return taskloaf.ready(1)
     else:
         return (fib(i - 1)
             .then(lambda a: fib(i - 2).then(lambda b: a + b))
             .unwrap())
Ejemplo n.º 4
0
def fib(index):
    if index < 3:
        return tl.ready(1)
    else:
        return tl.when_all(fib(index - 1), fib(index - 2)).then(add)
Ejemplo n.º 5
0
def test_ready():
    ctx = taskloaf.launch_local(1)
    fut1 = taskloaf.ready(2)
    assert(fut1.get() == 2)
Ejemplo n.º 6
0
def test_then():
    ctx = taskloaf.launch_local(1)
    assert(taskloaf.ready(2).then(lambda x: x + 1).get() == 3)