Kotlin Map collection with flatMap(), flatMapTo() methods

kotlin-map-collection-flatmap-flatmapto-methods-feature-image

In the tutorial, JavaSampleApproach will show you how to work with Kotlin Map flatMap() and flatMapTo() methods.

I. Kotlin Map collection with flatMap(), flatMapTo()

1. with flatMap() method

We use flatMap() to create a single list of all entries from results of [transform] function being invoked on each entry of original map.

Method signature:

Practice:

2. with flatMapTo() method

We use flatMapTo() to append all elements from results of [transform] function being invoked on each entry of given map, to the given [destination] mutable collection.

Method signature:

Practice:

II. Full Sourcecode



By grokonez | January 16, 2018.

Last updated on September 6, 2018.



Related Posts


Got Something To Say:

Your email address will not be published. Required fields are marked *

*