enum class Daypart {
MORNING, AFTERNOON, EVENING
}
class Event(
val title: String,
val description: String? = null,
val daypart: Daypart,
val duration: Int
)
val event1 = Event(title = "Wake up", description = "Time to get up", daypart = Daypart.MORNING, duration = 0)
val event2 = Event(title = "Eat breakfast", daypart = Daypart.MORNING, duration = 15)
val event3 = Event(title = "Learn about Kotlin", daypart = Daypart.AFTERNOON, duration = 30)
val event4 = Event(title = "Practice Compose", daypart = Daypart.AFTERNOON, duration = 60)
val event5 = Event(title = "Watch latest DevBytes video", daypart = Daypart.AFTERNOON, duration = 10)
val event6 = Event(title = "Check out latest Android Jetpack library", daypart = Daypart.EVENING, duration = 45)
val shortEvent = events.groupBy {
it.duration < 60
}
fun main() {
println(events.size)
println("You have ${shortEvent.size} short events")
}
prints I have six events but when I print short events it prints 2 I reversed the less than and get the expected 1 as there is only one duration with 60 tried android studio scratch,kotlin playground and the android playground all giving the same bug.
when you groupby it.duration < 60, it returns a map with two keys: either true or false, so the size is 2, it is ok.
To access short events' count, use shortEvent[true] and have a look.
enum class Daypart { MORNING, AFTERNOON, EVENING } class Event( val title: String, val description: String? = null, val daypart: Daypart, val duration: Int )
val event1 = Event(title = "Wake up", description = "Time to get up", daypart = Daypart.MORNING, duration = 0) val event2 = Event(title = "Eat breakfast", daypart = Daypart.MORNING, duration = 15) val event3 = Event(title = "Learn about Kotlin", daypart = Daypart.AFTERNOON, duration = 30) val event4 = Event(title = "Practice Compose", daypart = Daypart.AFTERNOON, duration = 60) val event5 = Event(title = "Watch latest DevBytes video", daypart = Daypart.AFTERNOON, duration = 10) val event6 = Event(title = "Check out latest Android Jetpack library", daypart = Daypart.EVENING, duration = 45)
val events = mutableListOf( event1, event2, event3, event4, event5, event6 )
val shortEvent = events.groupBy { it.duration < 60 } fun main() { println(events.size) println("You have ${shortEvent.size} short events") } prints I have six events but when I print short events it prints 2 I reversed the less than and get the expected 1 as there is only one duration with 60 tried android studio scratch,kotlin playground and the android playground all giving the same bug.