Adnan Ali
03/05/2020, 11:28 AMdata class Products(id){
packList=ArrayList<Packs>
}
data class Pack(title: string, is_original: Boolean)
val list= productList.map { it.id to it.packlist.map{ if (it.is_original==true} it.title}
Note: ArrayList<Products>
But Products= Arraylist<Pack>
i.e I want a hashmap just like this ["1" , "[item1, item2, item3, item4]" ]Dominaezzz
03/05/2020, 12:37 PMMap<String, String>
?Adnan Ali
03/05/2020, 12:38 PMDominaezzz
03/05/2020, 12:39 PMassociate
.Dominaezzz
03/05/2020, 12:40 PMmap
with associate
.Adnan Ali
03/05/2020, 12:42 PMassociate
Adnan Ali
03/05/2020, 12:46 PMif (it.is_original==true) it.title
But this if check is still bypassing, I just want to return list of those pack which have flag is_original= true
Dominaezzz
03/05/2020, 12:50 PMFranSoto
03/05/2020, 1:05 PMAdnan Ali
03/05/2020, 1:07 PMZach Klippenstein (he/him) [MOD]
03/05/2020, 2:48 PMmapNotNull
to do a filter + map at the same time:
productList.associate { (id, packlist) ->
id to packlist.mapNotNull { (title, isOriginal) ->
title.takeIf { isOriginal }
}
}
Adnan Ali
03/06/2020, 6:15 AM