Hackintoshfive
04/13/2023, 4:17 PMval (rootMountedOrSystemRoot, hasSystemPartition) = lines.fold(false to false) { acc, it ->
(
acc.first
|| it.device == "/dev/root" && it.mountpoint == "/"
|| it.mountpoint == "/system_root" && it.type != "tmpfs"
) to (
acc.second
|| it.mountpoint == "/system" && it.type != "tmpfs" && it.device != "none"
)
}
There's a more generic version in the comments(0 until 10).fold(false to false) { acc, it ->
(
acc.first
|| it.mod(2) == 0
) to (
acc.second
|| it.mod(3) == 0
|| it.mod(5) == 1
)
}
Adam S
04/13/2023, 5:03 PMany {}
and two variables.
val values = (0 until 10)
val hasEvenNumbers = values.any { it % 2 == 0 }
val hasFooNumbers = values.any { it % 3 == 0 || it % 5 == 1 }
return hasEvenNumbers to hasFooNumbers
sciack
04/13/2023, 5:06 PMit
type (or extension function) that return true/false based on the 3 original condition, this make everything more readable (if the function has a good name).Hackintoshfive
04/13/2023, 5:36 PMWout Werkman
04/13/2023, 6:12 PM(0 until 10).fold(false to false) { (evenNumbersFound, fooNumbersFound), it ->
sciack
04/13/2023, 6:15 PMHackintoshfive
04/14/2023, 9:19 AMsciack
04/14/2023, 9:24 AMWout Werkman
04/14/2023, 9:24 AMrunningFold
and takeWhile
iterator.asSequence()
.runningFold { acc, it -> /* operation here */ }
.takeWhile { (left, right) -> !(left && right) } // Will stop as soon as both are true
.last()
Hackintoshfive
04/14/2023, 9:30 AMWout Werkman
04/14/2023, 9:32 AMHackintoshfive
04/14/2023, 9:35 AMWout Werkman
04/14/2023, 9:38 AMHackintoshfive
04/14/2023, 10:01 AM