Example #1
0
        def create():
            def func(acc, x):
                if acc is None:
                    acc = 0
                return of(acc + x)

            return xs.pipe(_.merge_scan(func))
Example #2
0
def _files_in_path(credentials, path, retries):
    def find_with_parent(parent, name):
        return (list_folder(credentials, parent, name_filter=name, retries=retries) if parent else of([])).pipe(
            first(),  # There might be more than one file with the same name - we just take the first
            map(lambda files: files[0] if len(files) else None)
        )

    return _path_elements(path).pipe(
        merge_scan(find_with_parent, _root_folder)
    )
Example #3
0
def create_folder_with_path(credentials, path: str):
    def create_if_missing(parent, name_file):
        name = name_file[0]
        file = name_file[1]
        if file:
            return of(file)
        else:
            return create_folder(credentials, parent, name)

    return zip(
        _path_elements(path),
        _files_in_path(credentials, path),
    ).pipe(merge_scan(create_if_missing, _root_folder), last())
Example #4
0
    def test_merge_scan_concurrent(self):
        accumulator_calls = [0]

        def accumulator(acc, x):
            accumulator_calls[0] += 1
            return of(acc + x)

        xs = from_list([1, 2, 3, 4, 5]).pipe(_.merge_scan(accumulator, seed=0))

        results = TestSubscriber(xs).results()
        assert len(results) == 6
        assert results[0].value.kind == 'N' and results[0].value.value == 1
        assert results[1].value.kind == 'N' and results[1].value.value == 1 + 2
        assert results[2].value.kind == 'N' and results[
            2].value.value == 1 + 2 + 3
        assert results[3].value.kind == 'N' and results[
            3].value.value == 1 + 2 + 3 + 4
        assert results[4].value.kind == 'N' and results[
            4].value.value == 1 + 2 + 3 + 4 + 5
        assert results[5].value.kind == 'C'
        assert accumulator_calls[
            0] == 5  # Accumulator os not called more often than needed
Example #5
0
 def create():
     return xs.pipe(_.merge_scan(lambda acc, x: of(acc + x), seed=seed))
Example #6
0
 def create():
     return xs.pipe(_.merge_scan(seed, lambda acc, x: of(acc + x)))
Example #7
0
        def create():
            def func(acc, x):
                return of(acc + x)

            return never().pipe(_.merge_scan(seed=seed, accumulator=func))
Example #8
0
 def create():
     return never().pipe(_.merge_scan(lambda acc, x: of(acc + x)))