-
-
Notifications
You must be signed in to change notification settings - Fork 27
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 a way to map a Sub
message to multiple ones
#274
Comments
Hi! Yes, so currently I guess what you'd need to do is make a Msg that contains a list of the sub messages and then on model update, either fire them off individually or process the batch.
Indeed, Cmd's and Sub's are not monadic. Sub's making other subs sounds dubious. What you want - I think - is not more sub's but a way to return multiple messages from your sub? Have a read that right? |
Yes this is my current workaround althrough I'd like this "implementation detail" to not leak.
Yes. A way to map a single message produced by a In my use case, I have a |
Great, thanks. You can I'll look into it as soon as I'm back in Tyrian mode.. 😅 |
I've had another think about this, and also tried implementing it and my conclusion is... I need to think about it a bit more. 🙂 The use case here is quite specific: The general case is that something happened, or it didn't, and if it did, please let the main app logic know so that it can be dealt with. Now.... The workaround, is to put the many-part server messages into a single Sometimes I myself make issues that express some frustration with the APIs while I'm trying to do something, and then close them once I've stopped to think about the implications of the change and what it all means. I'm not saying this is definitely one of those times, but it feels a bit like it might be. More thought needed. |
Currently, it is not possible to map a value produced by a
Sub
to multiple ones, which could be useful in many cases.Here is my own use case: I am making a Scala wrapper for Pokemon Showdown's API. The messages sent by the server look like this:
in a single text frame.
WebSocket#subscribe
returns aSub[F, WebSocketEvent]
(excluding the mapping function asked in parameter) and I'd like to be able to turn thisWebSocketEvent
into multipleServerMessage
(from my API).My first intuition was to use
flatMap
+Sub.combine
but the former method does not exist and looking at the architecture ofSub
, I'm not sure if it is possible to implement it cleanly.Another approach would be to introduce a
Sub[F, A]#mapMultiple
(or similar name) taking aA => Iterable[B]
and returning aSub[F, B]
.The text was updated successfully, but these errors were encountered: