Hi, I'm just wandering, why there is no `Flow.flat...
# coroutines
d
Hi, I'm just wandering, why there is no
Flow.flatMap
operator? I know that direct replacement for it is
Flow.flatMapMerge
, but I'm still wandering why the team decided to avoid regular
flatMap
naming for particular operator in a favor of, well, a longer and more self-describing name. For me it's kinda weird trying to name basically the same thing differently, especially from the common to other libraries and languages perspective. Not trying to convince anybody to rename the operator, just searching for the reasoning.
d
Because with asynchronicity involved there is more than one variant of flatmap. And
flatMapMerge
is just one of them. RXJS does something similar, it has
mergeMap
,
switchMap
and
concatMap
, all of which could be called "flatMap".
d
That's true, but still we can assume that flatMap is just a default merging strat. If you need a more specific one you are just using
flatMapLatest
or
flatMapMerge
. For me the concern is that newcomers just going for
flatMap
, which is deprecated. And while IDE is a brilliant tool and will teach you in 1 min that the replacement is a
flatMapMerge
, it's still a confusing thing.
And the weirdest thing: 'old regular'
flatMap
is deprecated, and
flatMapMerge
is FlowPreview scoped. That should hit hard an unprepared for experimental APIs person.
o
flatMap
was never actually used, it only exists so that the IDE can steer people looking for
flatMap
towards the more explicit naming of
flatMap(Concat|Merge|Latest)
with the replacement quick fix.
Copy code
@Deprecated(
    level = DeprecationLevel.ERROR,
    message = "Flow analogue is 'flatMapConcat'",
    replaceWith = ReplaceWith("flatMapConcat(mapper)")
)
c
That just pollutes the auto completion.
d
Thanks @okarm . I knew that flatMap was never a thing for Flow. My question is directed towards reasoning of why not to pick such a logical name and instead polute autocompolete with "deprecated" operators. That's is a confusing thing.