Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runningFold function to Flow #2641

Closed
jakobulbrich opened this issue Apr 10, 2021 · 4 comments
Closed

Add runningFold function to Flow #2641

jakobulbrich opened this issue Apr 10, 2021 · 4 comments

Comments

@jakobulbrich
Copy link

jakobulbrich commented Apr 10, 2021

Kotlin supports the following functions on Collections

  • reduce and runningReduce
  • fold and runningFold

whereas Flows only support

  • reduce and runningReduce
  • fold and ???

Turns out the function is called scan, which is not consistent with the known naming scheme and hard to find. The scan function also exists for Collections but only acts as an alias for runningFold there.

It would be helpful to also add the runningFold function to Flows.

@pacher
Copy link

pacher commented Apr 10, 2021

Well, just to be fair, coming from RxJava it is much easier to find scan than runningFold, also for Collections :)

@qwwdfsad
Copy link
Member

Thanks for pointing it out!

Well, just to be fair, coming from RxJava it is much easier to find scan than runningFold

Indeed! This alias exists for better discoverability for people who came from reactive frameworks.
But we weren't really happy with the name scan. It doesn't have any reasonable rationale now, the name came from APL where \ operator with the same semantics was called scan , probably due to similarity to "scanning line".

qwwdfsad added a commit that referenced this issue Apr 12, 2021
    * Otherwise Kotlin users with non-reactive background get confused by flow/stdlib inconsistency
    * Make it experimental to delay the final decision about the name

Fixes #2641
@pacher
Copy link

pacher commented Apr 12, 2021

True, the name scan was puzzling at first in rx, but it is nice and short and we are quite used to it now.
What I mean is please keep it as an alias to runningFold, I would prefer keep using scan despite the lack of reasonable rationale ;-)

@sebastianharder
Copy link

@qwwdfsad the KDoc of runningFold refers to the scan function.

pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
…n#2645)

* Otherwise Kotlin users with non-reactive background get confused by flow/stdlib inconsistency
    * Make it experimental to delay the final decision about the name

Fixes Kotlin#2641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants