Beispiel #1
0
def test_seq_pipeline(xs: List[int]):
    ys = seq.of(xs).pipe(
        seq.map(lambda x: x * 10),
        seq.filter(lambda x: x > 100),
        seq.fold(lambda s, x: s + x, 0),
    )
    assert ys == functools.reduce(lambda s, x: s + x, filter(lambda x: x > 100, map(lambda x: x * 10, xs)), 0)
Beispiel #2
0
def test_seq_choose_option():
    xs: Iterable[Optional[int]] = seq.of(None, 42)

    chooser = seq.choose(option.of_optional)
    ys = pipe(xs, chooser)

    assert list(ys) == [42]
Beispiel #3
0
def test_seq_fold_fluent(xs: List[int], s: int):
    value = seq.of(xs).fold(lambda s, v: s + v, s)

    assert value == sum(xs) + s
Beispiel #4
0
def test_seq_fold_pipe(xs: List[int], s: int):
    folder: Callable[[int, int], int] = lambda s, v: s + v
    value = pipe(seq.of(xs), seq.fold(folder, s))

    assert value == sum(xs) + s
Beispiel #5
0
def test_seq_head_fluent(xs: List[int]):
    value = seq.of(xs).head()

    assert value == xs[0]
Beispiel #6
0
def test_seq_scan_fluent(xs: List[int], s: int):
    func: Callable[[int, int], int] = lambda s, v: s + v
    value = seq.of(xs).scan(func, s)

    assert list(value) == list(accumulate(xs, func, initial=s))
Beispiel #7
0
def test_seq_choose_option_fluent():
    xs = seq.of(None, 42)

    ys = xs.choose(option.of_optional)

    assert list(ys) == [42]