Skip to content

Instantly share code, notes, and snippets.

@blessedbyjobs
Created April 7, 2020 15:16
Show Gist options
  • Save blessedbyjobs/6cdfc280d7951534e8f8ad182d81d328 to your computer and use it in GitHub Desktop.
Save blessedbyjobs/6cdfc280d7951534e8f8ad182d81d328 to your computer and use it in GitHub Desktop.
data class Category(val id: Int, val name: String, val subCategories: List<SubCategory>)
data class SubCategory(val name: String)
data class Product(val value: Int, val category: SubCategory)
private fun getSubCategories(id: Int) = Observable.just(categories.first { it.id == id }.subCategories)
private fun getProductsByCategories() {
getSubCategories(categoryId)
.flatMap { categories -> products.filter { it.category in categories }.toObservable()}
.subscribe { Log.i("Products: ", it.toString()) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment