Skip to content

flatMap vs map + switchToLatest #132

Open
@mycroftcanner

Description

@mycroftcanner

If you want to use data provided by a publisher as a parameter or input to creating this publisher, there are two common means of enabling this:

Using the flatMap operator, using the data passed in to create or return a Publisher instance. This is a variation of the pattern illustrated in Using flatMap with catch to handle errors.

Alternately, map or tryMap can be used to create an instance of a publisher, followed immediately by chaining switchToLatest to resolve that publisher into a value (or values) to be passed within the pipeline.

The difference between the two alternative ways to create a publisher should be clearer.

When is it okay to use flatMap and when is it okay to use switchToLatest?

This is quite confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions