Esempio n. 1
0
 def zip(self) -> None:
     a = 1
     b = 2
     ab = (a, b)
     l1 = LazyList((a, a, a, a), chunk_size=1)
     l2 = LazyList((b, b, b, b), chunk_size=1)
     l1[1]
     z = l1.zip(l2)
     z.strict.should.equal(List(ab, ab))
     z.drain.should.equal(List(ab, ab, ab, ab))
Esempio n. 2
0
def episode_enumeration_match(filename):
    custom_rex = ConfigClient('series')('enumeration_regex')
    if custom_rex:
        return re.search(custom_rex, str(filename))
    else:
        if isinstance(filename, Path):
            filename = filename.name
        searcher = lambda s: re.search(s, filename, re.I)
        rex = LazyList(map(searcher, regexes))
        return rex.find(lambda a: a) | None
Esempio n. 3
0
 def search(self, monitor):
     return (
         LazyList(self._queries(monitor))
         .filter(_.valid)
         .apzip(self._safe_search)
         .map2(L(SearchResults)(_, _, self.min_seeders, self.max_size))
     )
Esempio n. 4
0
    def collect(self) -> None:
        def f(a: int, n: str) -> Maybe[str]:
            return Just(n) if a % 2 == 0 else Nothing

        l: LazyList = LazyList((a, str(a)) for a in range(10))
        l2 = l.collect(tupled2(f))
        l2.drain.should.equal(List('0', '2', '4', '6', '8'))
Esempio n. 5
0
 def zip(self, fa: LazyList[A], fb: LazyList[B], *fs) -> LazyList:
     fss = (fa, fb) + fs
     maxlen = max(map(lambda a: len(a.strict), fss))
     for f in fss:
         f._fetch(maxlen - 1)
     stricts = map(_.strict, fss)
     strict = ListZip().zip(*stricts)
     return LazyList(self._zip(fss), init=strict)
Esempio n. 6
0
 def slice_finite(self) -> None:
     l = LazyList(range(30), chunk_size=20)
     l[:15].should.have.length_of(15)
     l.strict.should.have.length_of(20)
     l[:20].should.have.length_of(20)
     l.strict.should.have.length_of(20)
     l[:21].should.have.length_of(21)
     l.strict.should.have.length_of(30)
Esempio n. 7
0
 def slice_infinite(self) -> None:
     l = LazyList(itertools.count(), chunk_size=20)
     l[:15].should.have.length_of(15)
     l.strict.should.have.length_of(20)
     l[:20].should.have.length_of(20)
     l.strict.should.have.length_of(20)
     l[:21].should.have.length_of(21)
     l.strict.should.have.length_of(40)
Esempio n. 8
0
 def flat_map(self, fa: LazyList[A],
              f: Callable[[A], LazyList[B]]) -> LazyList[B]:
     a, b = itertools.tee(fa.source)
     fa.source = a
     strict_m = fa.strict.map(f)
     lazy_m = map(f, b)
     mapped = itertools.chain(strict_m, lazy_m)
     source = itertools.chain.from_iterable(mapped)
     return LazyList(source, List(), fa._chunk_size)
Esempio n. 9
0
 def filter(self) -> None:
     l = LazyList(range(30))
     l2 = l.filter(_ % 2 == 0)
     l2.strict.should.have.length_of(0)
     l3 = LazyList(range(30))
     l3[29]
     l4 = l3.filter(_ % 2 == 0)
     l4.strict.should.have.length_of(15)
     l4.drain.should.equal(List.wrap(range(0, 30, 2)))
Esempio n. 10
0
 def apzip(self) -> None:
     l = LazyList((1, 2, 3), chunk_size=1)
     l[0]
     z = l.apzip(_ + 2)
     z.drain.should.equal(List((1, 3), (2, 4), (3, 5)))
Esempio n. 11
0
 def traverse_task(self) -> None:
     n = 3
     l = LazyList(range(n))
     result = l.traverse(Task.now, Task).attempt / _.drain
     result.should.contain(l.drain)
Esempio n. 12
0
 def sequence(self) -> None:
     n = 3
     l = LazyList(map(Just, range(n)))
     target = LazyList(List.wrap(range(n)))
     (l.sequence(Maybe) / _.drain).should.contain(target.drain)
Esempio n. 13
0
 def traverse_io(self) -> None:
     n = 3
     l = LazyList(range(n))
     result = l.traverse(IO.now, IO).attempt / _.drain
     result.should.contain(l.drain)
Esempio n. 14
0
 def find(self) -> None:
     l = LazyList(range(30), chunk_size=20)
     l.find(_ == 21).should.contain(21)
     l.find(_ == 49).should.be.empty
Esempio n. 15
0
 def index_of(self) -> None:
     l = LazyList(range(30), chunk_size=20)
     l.index_of(21).should.contain(21)
     l.index_of(49).should.be.empty
Esempio n. 16
0
 def with_index(self) -> None:
     l = LazyList(itertools.count(), chunk_size=20)
     l2 = l.map(_ * 5).with_index
     l2[:2].should.equal(List((0, 0), (1, 5)))
Esempio n. 17
0
 def map(self) -> None:
     l = LazyList(itertools.count(), chunk_size=20)
     l.lift(5)
     l2 = l.map(_ * 10)
     l2[:5].should.equal(List.wrap(range(0, 50, 10)))
Esempio n. 18
0
 def single(self) -> None:
     l = LazyList(range(30), chunk_size=20)
     l[19].should.equal(19)
     l.strict.should.have.length_of(20)
     l[20].should.equal(20)
     l.strict.should.have.length_of(30)
Esempio n. 19
0
 def pure(self, a: A):
     return LazyList([], List(a))
Esempio n. 20
0
 def deep(self) -> None:
     n = int(1e4)
     l = LazyList(List.wrap(range(n)))
     l.index_of(n - 1).should.contain(n - 1)
Esempio n. 21
0
 def with_index(self, fa: LazyList[A]) -> List[Tuple[int, A]]:
     return LazyList(enumerate(fa.source), fa.strict, fa._chunk_size)
Esempio n. 22
0
def nodes(*s: Tuple[Data, Callable[[RoseTree[Data]], RoseTree[Data]]]
          ) -> Callable[[RoseTree[Data]], LazyList[RoseTree[Data]]]:
    return lambda parent: LazyList(s).map2(node).map(lambda f: f(parent))
Esempio n. 23
0
 def sub_l(self) -> LazyList[Node[Data, Any]]:
     return LazyList([])
Esempio n. 24
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))
Esempio n. 25
0
def leaves(*data: Data) -> Callable[[RoseTree[Data]], LazyList[RoseTree[Data]]]:
    return lambda parent: LazyList(data).map(leaf).map(lambda f: f(parent))
Esempio n. 26
0
 def fold_left(self) -> None:
     LazyList((1, 2, 3)).fold_left('')(lambda a, b: str(b) + a)\
         .should.equal('321')
Esempio n. 27
0
 def strings(self) -> LazyList[str]:
     return LazyList([])
Esempio n. 28
0
 def fold_map(self) -> None:
     LazyList((1, 2, 3)).fold_map(5, _ * 2).should.equal(17)