Skip to content

Commit

Permalink
polish *tuple docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hjtran committed Dec 6, 2024
1 parent d379968 commit 1afda2b
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions sdks/python/apache_beam/transforms/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2117,15 +2117,13 @@ def MapTuple(fn, *args, **kwargs): # pylint: disable=invalid-name
r""":func:`MapTuple` is like :func:`Map` but expects tuple inputs and
flattens them into multiple input arguments.
beam.MapTuple(lambda a, b, ...: ...)
In other words
beam.MapTuple(fn)
"SwapKV" >> beam.Map(lambda kv: (kv[1], kv[0]))
is equivalent to
beam.Map(lambda element, ...: fn(\*element, ...))
"SwapKV" >> beam.MapTuple(lambda k, v: (v, k))
This can be useful when processing a PCollection of tuples
(e.g. key-value pairs).
Expand Down Expand Up @@ -2191,19 +2189,13 @@ def FlatMapTuple(fn, *args, **kwargs): # pylint: disable=invalid-name
r""":func:`FlatMapTuple` is like :func:`FlatMap` but expects tuple inputs and
flattens them into multiple input arguments.
beam.FlatMapTuple(lambda a, b, ...: ...)
is equivalent to Python 2
beam.FlatMap(lambda (a, b, ...), ...: ...)
In other words
beam.FlatMapTuple(fn)
beam.FlatMap(lambda start_end: range(start_end[0], start_end[1]))
is equivalent to
beam.FlatMap(lambda element, ...: fn(\*element, ...))
beam.FlatMapTuple(lambda start, end: range(start, end))
This can be useful when processing a PCollection of tuples
(e.g. key-value pairs).
Expand Down

0 comments on commit 1afda2b

Please sign in to comment.