You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "GodefroyClair (via GitHub)" <gi...@apache.org> on 2023/03/11 10:18:53 UTC

[GitHub] [beam] GodefroyClair opened a new issue, #25807: Why is FlatMap not Flatten + Map?

GodefroyClair opened a new issue, #25807:
URL: https://github.com/apache/beam/issues/25807

   Maybe I'm not asking at the right place but I am quite surprised about the way `Flatten()` and `FlatMap()` are implemented in Python.
   Normally, in functional progamming (Haskell, Scala...), FlatMap() should be the same as composing `Flatten()` and `Map()`.
   But in Apache Beam, Flatten() is using _iterable of PCollections_ while FlatMap() is working with _PCollection of Iterables_.
   
   ```
   Flatten:: Iterable[PCollections[A]] -> PCollection[A]
   Map:: (PCollection[A], (A-> B)) -> PCollection[B]
   
   FlatMap:: (PCollection[Iterable[A]], (A->B)) -> [A]
   ```
   
   So my question is is there another Flatten with this signature :
   anotherFlatten:: PCollection[Iterable[A]] -> PCollection[A]
   
   One of the reason this would be useful, is that when you just want to use `Flatten` a `PCollection` of `iterable` you have to use `FlatMap()`with an identity function (for example to use empty list as an alternative to the [Maybe/Optional Monad](https://blog.ploeh.dk/2022/04/25/the-maybe-monad/) Pattern)
   
   So instead of writing:
   `FlatMap(lambda e: e)`
   I would like to have a function
   `anotherFlatten()`
   
   Plus this is not helping when you are trying to teach functional programming with Apache Beam to Pythonist... it kinds of break the intuition about FlatMap.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] aromanenko-dev closed issue #25807: Why is FlatMap different from composing Flatten and Map?

Posted by "aromanenko-dev (via GitHub)" <gi...@apache.org>.
aromanenko-dev closed issue #25807: Why is FlatMap different from composing Flatten and Map?
URL: https://github.com/apache/beam/issues/25807


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [beam] aromanenko-dev commented on issue #25807: Why is FlatMap different from composing Flatten and Map?

Posted by "aromanenko-dev (via GitHub)" <gi...@apache.org>.
aromanenko-dev commented on issue #25807:
URL: https://github.com/apache/beam/issues/25807#issuecomment-1466275172

   Since it's not an issue and just a question for discussion, could you ask this on [user@beam.apache.org](https://lists.apache.org/list.html?user@beam.apache.org)?
   Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org