https://kotlinlang.org logo
Title
x

xenoterracide

03/19/2019, 7:48 PM
list.map { arrayOf(it.rfid.rfid, it.pressureSignal, it.uoPressure, it.chamberPressure, it.ultrasonicSignal, it.rfid.timestamp) }
given this map, I want to flatten the whole list into one big array (no nested arrays), but I’m not sure how to take each element of this array and map it to just an element
d

diesieben07

03/19/2019, 7:48 PM
flatMap
?
x

xenoterracide

03/19/2019, 7:49 PM
but flatmap what?
d

diesieben07

03/19/2019, 7:49 PM
Same as in Java? 😄
Or really you can just use
flatMap
in place of
map
in this case
x

xenoterracide

03/19/2019, 7:49 PM
I don’t have a stream here though?
d

diesieben07

03/19/2019, 7:49 PM
Kotlin's List already has flatMap
No need for a stream.
s

Shawn

03/19/2019, 7:50 PM
right, you don’t need an intermediate stream
I feel like there’s something about the shape of your list I don’t understand, given your question
x

xenoterracide

03/19/2019, 7:51 PM
it’s just a list of objects, and I want to take the properties and map it into one big list
d

diesieben07

03/19/2019, 7:51 PM
Yeah. That's what
flatMap
does.
x

xenoterracide

03/19/2019, 7:51 PM
I feel like I’m missing some obvious to not me syntax with flatmap
list.flatMap {
            it.rfid.rfid,
            it.pressureSignal,
            it.uoPressure,
            it.chamberPressure,
            it.ultrasonicSignal,
            it.rfid.timestamp
         }
that obviously won’t work
d

diesieben07

03/19/2019, 7:52 PM
You have to return a list.
x

xenoterracide

03/19/2019, 7:52 PM
ah
so return listOf instead of arrayOf?
s

Shawn

03/19/2019, 7:53 PM
yep
x

xenoterracide

03/19/2019, 7:53 PM
ok, that’s what I was missing, I knew it was something dumb…