chore: Avoid copy the whole iterable for mapconcat and statefulMapConcat in javadsl. (#1250)

This commit is contained in:
He-Pin(kerr) 2024-04-05 23:53:59 +08:00 committed by GitHub
parent 24e47b8cac
commit f39ab64439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -744,9 +744,7 @@ final class Flow[In, Out, Mat](delegate: scaladsl.Flow[In, Out, Mat]) extends Gr
* '''Cancels when''' downstream cancels
*/
def mapConcat[T](f: function.Function[Out, java.lang.Iterable[T]]): javadsl.Flow[In, T, Mat] =
new Flow(delegate.mapConcat { elem =>
Util.immutableSeq(f(elem))
})
new Flow(delegate.mapConcat(f(_).asScala))
/**
* Transform each stream element with the help of a state.
@ -900,7 +898,7 @@ final class Flow[In, Out, Mat](delegate: scaladsl.Flow[In, Out, Mat]) extends Gr
f: function.Creator[function.Function[Out, java.lang.Iterable[T]]]): javadsl.Flow[In, T, Mat] =
new Flow(delegate.statefulMapConcat { () =>
val fun = f.create()
elem => Util.immutableSeq(fun(elem))
elem => fun(elem).asScala
})
/**