Skip to content

Instantly share code, notes, and snippets.

@EmmanuelGuther
Last active March 3, 2022 18:09
Show Gist options
  • Save EmmanuelGuther/ae891e868bcee4dbc3cc340b0513f10a to your computer and use it in GitHub Desktop.
Save EmmanuelGuther/ae891e868bcee4dbc3cc340b0513f10a to your computer and use it in GitHub Desktop.
val selectedSubcategories = selectedCategories.asSequence().map { it?.subCategories }.fold(mutableSetOf<SubCategoryModel>()) { acc, list ->
list?.asSequence()?.filter { it.checked }?.map { acc.add(it) }?.toList()
acc
}
val subcategoriesJoined = selectedSubcategories.asSequence().map { it.name }.joinToString(separator = "")
editTextProfessionalRegisterCategories.setText(subcategoriesJoined)
@EmmanuelGuther
Copy link
Author

You have this list and you want all the names from within the sublists.

[ { "checked": false, "name": "Alpha" "subList": [ { "checked": false, "name": "leaks" }, { "checked": false, "name": "pipes" }, { "checked": false, "name": "toilets" }, { "checked": false, "name": "taps" } ] }, { "checked": false, "name": "Beta", "subList": [ { "checked": false, "name": "leaks" }, { "checked": false, "name": "pipes" }, { "checked": false, "name": "toilets" }, { "checked": false, "name": "taps" } ] } }]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment