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 StreamMessage.flatMap() #3966

Closed
sleeplesslord opened this issue Dec 2, 2021 · 3 comments · Fixed by #4227
Closed

Add StreamMessage.flatMap() #3966

sleeplesslord opened this issue Dec 2, 2021 · 3 comments · Fixed by #4227
Labels
new feature sprint Issues for OSS Sprint participants

Comments

@sleeplesslord
Copy link
Contributor

sleeplesslord commented Dec 2, 2021

StreamMessage has map which allows mapping the values in a stream with a function. It doesn't currently have flatMap so it's difficult to work with a function that itself returns a StreamMessage, for example when chaining multiple operations.

interface StreamMessage<T> {
    StreamMessage<U> flatMap(Function<T, StreamMessage<U>> function);
}
@sleeplesslord
Copy link
Contributor Author

I'll work on this and make a PR when it's ready 😄

@ikhoon
Copy link
Contributor

ikhoon commented Dec 2, 2021

JFYI, there is a difference in subscription between concatMap and flatMap.
ConcatArrayStreamMessage could be a good example for the flatMap operation.

@trustin
Copy link
Member

trustin commented Mar 28, 2022

Looking forward to this, @sleeplesslord! 🙇

@trustin trustin added the sprint Issues for OSS Sprint participants label Feb 16, 2023
ikhoon added a commit that referenced this issue Apr 9, 2024
Motivation:
`StreamMessage` has `map`, but it is inconvenient to use it when the
mapping function itself returns a `StreamMessage`. This PR adds
`flatMap` which allows applying a function that returns a
`StreamMessage` without ending up with nested `StreamMessage`s.

Modifications:
- Add `FlatMapStreamMessage`, which uses a function that returns a
`StreamMessage` to modify the stream.
- Add `StreamMessage.flatMap()` to allow easily creating a
`FlatMapStreamMessage` from an existing stream.

Result:
- Closes #3966 
- You can now use `StreamMessage.flatMap` to modify a stream using a
function that returns a `StreamMessage`.

---------

Co-authored-by: jrhee17 <guins_j@guins.org>
Co-authored-by: minwoox <songmw725@gmail.com>
Co-authored-by: Ikhun Um <ih.pert@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature sprint Issues for OSS Sprint participants
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants