therealbluepandabear
03/09/2021, 12:22 AMEndre Deak
03/09/2021, 12:26 AMEndre Deak
03/09/2021, 12:27 AM.distinct()
with the same assumptions)ephemient
03/09/2021, 12:28 AMlist.all { it == list.first() }
nanodeath
03/09/2021, 12:36 AM.asSequence().zipWithNext().any { a, b -> a != b }
therealbluepandabear
03/09/2021, 1:11 AMtherealbluepandabear
03/09/2021, 1:11 AMfun numbersEven(data: List<Int>) = data.toSet().size == 1
nanodeath
03/09/2021, 1:12 AMephemient
03/09/2021, 1:12 AMtherealbluepandabear
03/09/2021, 1:13 AMnanodeath
03/09/2021, 1:13 AMdata.asSequence().distinct().take(2).toList().size == 1
therealbluepandabear
03/09/2021, 1:17 AMephemient
03/09/2021, 2:01 AM.all
though? I do mean it, that if the contract is "all values of a list are equal to each other", it should be vacuously true for the empty listtherealbluepandabear
03/09/2021, 2:08 AMfor (string in asList) {
if (string != asList[asList.size - 1]) {
if (string[0] == 'Z' || string[0] == 'z') {
println(string)
}
}
}
Apologise if this is a strange question... again, I feel like there is more concise kotlin-like way of doing thistherealbluepandabear
03/09/2021, 2:09 AMtherealbluepandabear
03/09/2021, 2:11 AMasList
.asSequence()
.filter { it != asList[asList.size - 1] && (it[0] == 'Z' || it[0] == 'z') }
.forEach { println(it) }
ephemient
03/09/2021, 2:11 AMfor (string in asList) {
if (string != asList.last() && string.isNotEmpty() && string.first() in "Zz") {
println(string)
}
}
if you wanted to do it with the Kotlin collections extensions, you could certainly
asList.filter { string -> string != asList.last && string.firstOrNull()?.let("Zz"::contains) == true }.forEach(::println)
ephemient
03/09/2021, 2:11 AM.firstOrNull()
because [0]
will crash on an empty stringtherealbluepandabear
03/09/2021, 2:13 AMasList
.filter { it.isNotEmpty() && (it[0] == 'Z' || it[0] == 'z') }
.forEach { println(it) }
ephemient
03/09/2021, 2:14 AMtherealbluepandabear
03/09/2021, 2:15 AMephemient
03/09/2021, 2:15 AMif (string != asList[asList.size - 1])
ephemient
03/09/2021, 2:15 AMstring != asList.last()
therealbluepandabear
03/09/2021, 2:16 AM