Skip to content

Commit

Permalink
README: shorten concurrent flatten example
Browse files Browse the repository at this point in the history
  • Loading branch information
ebonnal committed Oct 16, 2024
1 parent 2a26a3e commit a2c73e8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 32 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,8 @@ assert list(pair_then_odd_integers) == [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]
> Flattens `concurrency` iterables concurrently:
```python
letters_mix: Stream[str] = Stream(
[
Stream(["a"] * 5).throttle(per_second=10),
Stream(["b"] * 5).throttle(per_second=10),
Stream(["c"] * 5).throttle(per_second=10),
]
).flatten(concurrency=2)
assert list(letters_mix) == ['a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b', 'c', 'c', 'c', 'c', 'c']
mix_of_0s_and_1s: Stream[int] = Stream([[0] * 4, [1] * 4]).flatten(concurrency=2)
assert list(mix_of_0s_and_1s) == [0, 1, 0, 1, 0, 1, 0, 1]
```


Expand Down
28 changes: 4 additions & 24 deletions tests/test_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,30 +150,10 @@ def test_flatten_example(self) -> None:
assert list(pair_then_odd_integers) == [0, 2, 4, 6, 8, 1, 3, 5, 7, 9]

def test_concurrent_flatten_example(self) -> None:
letters_mix: Stream[str] = Stream(
[
Stream(["a"] * 5).throttle(per_second=10),
Stream(["b"] * 5).throttle(per_second=10),
Stream(["c"] * 5).throttle(per_second=10),
]
).flatten(concurrency=2)
assert list(letters_mix) == [
"a",
"b",
"a",
"b",
"a",
"b",
"a",
"b",
"a",
"b",
"c",
"c",
"c",
"c",
"c",
]
mix_of_0s_and_1s: Stream[int] = Stream([[0] * 4, [1] * 4]).flatten(
concurrency=2
)
assert list(mix_of_0s_and_1s) == [0, 1, 0, 1, 0, 1, 0, 1]

def test_catch_example(self) -> None:
inverses: Stream[float] = integers.map(lambda n: round(1 / n, 2)).catch(
Expand Down

0 comments on commit a2c73e8

Please sign in to comment.