Skip to content

Commit

Permalink
add FlatMap generator example
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed Jul 3, 2023
1 parent dca99fd commit a32f664
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ Same as `FilterKeys` but for `v` in `(k, v)` pairs
>>> [range(0, 5), range(100, 105)] | FlatMap(yield_even) | Pipe(list)
[0, 2, 4, 100, 102, 104]

>>> [range(0, 5), range(100, 105)] | FlatMap(lambda it: (x for x in it if x % 2 == 0)) | Pipe(list)
[0, 2, 4, 100, 102, 104]

```

## FlatMapValues
Expand Down
1 change: 1 addition & 0 deletions tests/pipe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def test_filter_values(it, f, expected):
([0, 2, 3, 0, 4], range, [0, 1, 0, 1, 2, 0, 1, 2, 3]),
([2, 3, 4], lambda x: [(x, x), (x, x)], [(2, 2), (2, 2), (3, 3), (3, 3), (4, 4), (4, 4)]),
([range(0, 5), range(100, 105)], yield_even, [0, 2, 4, 100, 102, 104]),
([range(0, 5), range(100, 105)], lambda it: (x for x in it if x % 2 == 0), [0, 2, 4, 100, 102, 104]),
],
)
def test_flat_map(it, f, expected):
Expand Down

0 comments on commit a32f664

Please sign in to comment.