When..can I mix data types?

Can I mix data types in the when statement? For example like this?

fun whatToDo(dayOfWeek: Any) = when (dayOfWeek) {
"Saturday", “Sunday” || in 5…7 → “Relax”
in listOf(“Monday”, “Tuesday”, “Wednesday”, “Thursday”) || in 2…4 → “Work hard”
“Friday” → “Party”
is String → “What?”
else → “No clue”


println(whatToDo(“Sunday”)) //Relax
println(whatToDo(“Wednesday”)) //Work hard
println(whatToDo(1)) //Work hard
println(whatToDo(“Friday”)) //Party
println(whatToDo(“Munday”)) //What?
println(whatToDo(8)) //No clue

Hi @Ego
Thanks for reaching out to us. In Kotlin, the comma acts as an OR operator so we can make this code executable by using “,” instead of “||”. Here you go:

fun whatToDo(dayOfWeek: Any) =  when (dayOfWeek) {
  "Saturday", "Sunday", in 5..7 -> "Relax"
  in listOf("Monday", "Tuesday", "Wednesday", "Thursday"), in 2..4 -> "Work hard"
  "Friday" -> "Party"
  is String -> "What?"
  else -> "No clue"

println(whatToDo("Sunday")) //Relax
println(whatToDo("Wednesday")) //Work hard
println(whatToDo(3)) //Work hard
println(whatToDo("Friday")) //Party
println(whatToDo("Munday")) //What?
println(whatToDo(8)) //No clue

I hope it helps. Happy Learning :slight_smile: