Filter list of objects in RxJava

后端 未结 4 1714
南方客
南方客 2021-02-13 07:00

I am trying to filter the list on the basis of it\'s property. For example, Sensors class has a property isActive and I want to get all the objects with isAct

4条回答
  •  青春惊慌失措
    2021-02-13 07:11

    Kotlin users can use a more simple approach like below.

    fcService.getStationList()
        .map(it.filter {sensor -> sensor.isActive()})
    

    It is possible because Kotlin has so many list operators itself, so for the filtering part you don't have to use rx. it.filter {sensor -> sensor.isActive()} is pure Kotlin code.

提交回复
热议问题