예제 #1
0
파일: test_seq.py 프로젝트: exyi/Expression
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)
예제 #2
0
def test_seq_pipeline(xs: List[int]):
    mapper: Callable[[int], int] = lambda x: x * 10
    predicate: Callable[[int], bool] = lambda x: x > 100
    folder: Callable[[int, int], int] = lambda s, x: s + x

    ys = seq.of_iterable(xs).pipe(
        seq.map(mapper),
        seq.filter(predicate),
        seq.fold(folder, 0),
    )
    assert ys == functools.reduce(
        lambda s, x: s + x, filter(lambda x: x > 100,
                                   map(lambda x: x * 10, xs)), 0)
예제 #3
0
파일: test_seq.py 프로젝트: exyi/Expression
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