David Whittaker
07/28/2023, 4:21 PM{3=7, 2=8, 4=1}
turns into [7, 7, 7, 8, 8, 1, 1, 1, 1]
? My naive way is to create a mutableList
and iterate through the map using forEach
and `repeat`edly add
items to the list.Goetz Markgraf
07/28/2023, 4:32 PMval map = mapOf(3 to 7, 2 to 8, 4 to 1)
map.flatMap { (key, value) -> List(key) { value} }
this returns
[7, 7, 7, 8, 8, 1, 1, 1, 1]
David Whittaker
07/28/2023, 4:34 PMflatMap
was the key piece I was missing.David Whittaker
07/28/2023, 10:25 PMflatMap
once I've reached a list of size n?Vampire
07/28/2023, 10:53 PMtake(n)
, it should probably work.CLOVIS
07/29/2023, 11:50 AMDavid Whittaker
07/29/2023, 10:24 PMtake(4).forEach{ println("Result: $it") }
then the sequence will only produce 4 elements?Joffrey
07/29/2023, 11:04 PMCLOVIS
07/30/2023, 8:17 AM.onEach { println("$it") }
in the middle of the pipeline to see when elements are generated :)