concept true in category kotlin

This is an excerpt from Manning's book The Joy of Kotlin.
To stick with the idea that
Emptymeans optional data, you’d need to first filter the list to remove theEmptyelements. But for this, you’d need anisEmptyfunction in theResultclass returningtruein theEmptysubclass andfalseinSuccessandFailure:
The
0value is aPair<Result<A>, Int>with theIntvalue equal to-1(the first value smaller than0). Can you use a standardPairfor this? No, you can’t, because it must have a special equals function that returnstruewhen the integer values are equal, whatever theResult<A>is. The complete function is as follows:fun getAt(index: Int): Result<A> { data class Pair<out A>(val first: Result<A>, val second: Int) { override fun equals(other: Any?): Boolean = when { other == null -> false other.javaClass == this.javaClass -> (other as Pair<A>).second == second else -> false } override fun hashCode(): Int = first.hashCode() + second.hashCode() } return Pair<A>(Result.failure("Index out of bound"), index) .let { identity -> Pair<A>(Result.failure("Index out of bound"), -1).let { zero -> if (index < 0 || index >= length()) identity else foldLeft(identity, zero) { ta: Pair<A> -> { a: A -> if (ta.second < 0) ta else Pair(Result(a), ta.second - 1) } } } }.first }Now the fold automatically stops as soon as the searched-for element is found. You can use the new
foldLeftfunction for escaping any computation with a zero element. (Remember: zero not 0.) But instead of using a zero element, you can use a predicate and make the function return when this predicate returnstrue: