Sam Stone
10/23/2022, 2:46 AM2.repeat(init = 10) { acc -> acc * 10 } == 1_000
(to repeat 10*10 twice, or 10*10*10) instead of (0..1).fold(10) { acc, _ -> acc * 10 } = 1_000
ephemient
10/23/2022, 2:59 AMgenerateSequence(seed = 10) { acc -> acc * 10 }.drop(2).first() == 1_000
ephemient
10/23/2022, 2:59 AMvar
and loop; both fold and sequence create unnecessary iteratorsephemient
10/23/2022, 4:33 AMinline fun <T> repeat(times: Int, seed: T, nextFunction: (T) -> T): T {
var acc = seed
repeat(times) { acc = nextFunction(acc) }
return acc
}
but there's no standard function, and unfortunately due to the generic (even though it's inline) this results in unnecessary boxingDominaezzz
10/23/2022, 11:51 AMT
is reified
?ephemient
10/23/2022, 5:24 PM