Beispiel #1
0
 def loop(self) -> None:
     e = (LazyLists.range(1000).fold_left(
         eval.Now(0))(lambda z, a: z.flat_map(lambda a: eval.Now(a + 1))))
     e._value().should.equal(1000)
Beispiel #2
0
 def flatten(self) -> LazyList[Any]:
     return LazyLists.cons(self)
Beispiel #3
0
 def _strings(self) -> LazyList[Data]:
     return LazyLists.cons(self.data)
Beispiel #4
0
class StrLeaf(LeafNode[str], StrNode[None]):
    pass


class StrListNode(ListNode[str], StrNode[LazyList[Node[str, Any]]]):
    pass


class StrMapNode(MapNode[str], StrNode[Map[str, Node[str, Any]]]):
    pass


tree = StrListNode(
    LazyLists.cons(
        StrLeaf("leaf1"),
        StrListNode(LazyLists.cons(StrLeaf("sub1"), StrLeaf("sub2")))))
mtree = StrMapNode(Map(first=tree, second=StrLeaf('leaf2')))

show_target = '''[]
 leaf1
 []
  sub1
  sub2'''


class TreeSpec(Spec):
    def sub(self) -> None:
        t1 = tree.lift(1)
        t1.head.data.data.should.equal('sub1')
Beispiel #5
0
def leaf(data: Data) -> Callable[[RoseTree[Data]], RoseTree[Data]]:
    return lambda parent: BiRoseTree(data, parent, lambda a: LazyLists.empty())
Beispiel #6
0
 def flat_map(self) -> None:
     l = LazyLists.cons(LazyList((1, 2, 3)), LazyList((4, 5, 6)),
                        LazyList((1, 2, 3)))
     l.lift(1)
     l.flat_map(I).drain.should.equal(List(1, 2, 3, 4, 5, 6, 1, 2, 3))