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

More flow operators #248

Open
5 of 14 tasks
adamw opened this issue Nov 28, 2024 · 2 comments
Open
5 of 14 tasks

More flow operators #248

adamw opened this issue Nov 28, 2024 · 2 comments

Comments

@adamw
Copy link
Member

adamw commented Nov 28, 2024

Inspired by https://github.com/apache/pekko/blob/main/stream/src/main/scala/org/apache/pekko/stream/scaladsl/Flow.scala:

  • sample(n: Int) -> emit every nth element from the parent flow
  • zipWithIndex
  • debounce (remove subsequent, repeating elements)
  • debounceBy(T => U)
  • recover(Throwable => T) (emit one element when the stream fails)
  • recoverWith(Throwable => Flow) (start alternative flow on failure)
  • recoverWithRetry(RetryConfig)(Throwable => Flow)
  • mapWithResource(=> R, R => Option[U])((R, T) => U)
  • mapWithCloseableResource(=> R)((R, T) => U)
  • scan(V)((V, T) => T)
  • conflate
  • batch
  • expand
  • extrapolate
This was referenced Dec 13, 2024
@corem
Copy link
Contributor

corem commented Dec 16, 2024

@adamw Isn't thebatch behavior already implemented by: def grouped(n: Int): Flow[Seq[T]] ?

def grouped(n: Int): Flow[Seq[T]] = groupedWeighted(n)(_ => 1)

@adamw
Copy link
Member Author

adamw commented Dec 17, 2024

@corem hm batch might be a more challenging one. grouped always groups elements into groups of n elements (except maybe for stream completion), while batch does so only if the downstream consumer is slower. So in normal conditions you might not see any groups at all.

Implementing this would probably require some channels + select.

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

No branches or pull requests

2 participants