Bernhard
07/24/2024, 4:06 PMBernhard
07/24/2024, 4:15 PMBernhard
07/24/2024, 4:16 PMfun <T> Int.repeat(initial: T, block: (T) -> T): T {
var accumulator = initial
kotlin.repeat(this) {
accumulator = block(accumulator)
}
return accumulator
}Bernhard
07/24/2024, 4:18 PMYoussef Shoaib [MOD]
07/24/2024, 4:20 PM(0..2).fold(3) { it, _ -> it + 1 } but it's kinda ugly because it passes the index inKlitos Kyriacou
07/24/2024, 4:41 PMgenerateSequence(3) { it + 1 }.take(1 + 2).last() (it's 1 + 2 because the seed (3) is counted as the first element, and you want another 2).ephemient
07/25/2024, 4:26 AMgenerateSequence(3) { it + 1 }.elementAt(2)