Home > other >  Filter list of enums by multiple enum constants ("types" of the enum)[Kotlin]
Filter list of enums by multiple enum constants ("types" of the enum)[Kotlin]

Time:11-04

I have a list of enum constants (types) of the same enum object. How can I filter the list by multiple constants?

I have tried this:

val list = dataList.filter {
            when(it.type){
                Type.ACTIVE,
                Type.RENEWED,
                Type.OTHER -> {}
            }
        }

CodePudding user response:

this should work:

val list = dataList.filter {
    when(it.type){
        Type.ACTIVE,
        Type.RENEWED,
        Type.OTHER -> true
        else -> false
    }
}
  • Related