Skip to content

Commit

Permalink
add one more example for FlatMapValues
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed May 14, 2023
1 parent 7d84049 commit 2beeee3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ Same as `FilterKeys` but for `v` in `(k, v)` pairs
>>> [("a", ["x", "y", "z"]), ("b", ["p", "r"])] | FlatMapValues(lambda x: x) | Pipe(list)
[('a', 'x'), ('a', 'y'), ('a', 'z'), ('b', 'p'), ('b', 'r')]

>>> keep_even = lambda it: it | Filter(lambda x: x % 2 == 0)
>>> [('a', [0, 1, 2]), ('b', [3, 4])] | FlatMapValues(keep_even) | Pipe(list)
[('a', 0), ('a', 2), ('b', 4)]

```

## KeyBy
Expand Down
1 change: 1 addition & 0 deletions tests/pipe_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def test_flat_map(it, f, expected):
@pytest.mark.parametrize(
('it', 'f', 'expected'), [
([('a', ['x', 'y', 'z']), ('b', ['p', 'r'])], lambda x: x, [('a', 'x'), ('a', 'y'), ('a', 'z'), ('b', 'p'), ('b', 'r')]),
([('a', [0, 1, 2]), ('b', [3, 4])], yield_even, [('a', 0), ('a', 2), ('b', 4)]),
],
)
def test_flat_map_values(it, f, expected):
Expand Down

0 comments on commit 2beeee3

Please sign in to comment.