Skip to content

Add a way to map a Sub message to multiple ones #274

@Iltotore

Description

@Iltotore

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:

>roomid
message1
message2
...

in a single text frame.

WebSocket#subscribe returns a Sub[F, WebSocketEvent] (excluding the mapping function asked in parameter) and I'd like to be able to turn this WebSocketEvent into multiple ServerMessage (from my API).

My first intuition was to use flatMap+Sub.combine but the former method does not exist and looking at the architecture of Sub, 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 a A => Iterable[B] and returning a Sub[F, B].

Metadata

Metadata

Assignees

No one assigned

    Labels

    under considerationThe issue needs time to mature and ripen in the minds of those considering it.workaround

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions