Got a suggestion to create a cheat sheet showing h...
# random
t
Got a suggestion to create a cheat sheet showing how to convert math symbols and expressions into Kotlin code. Here's the start, contributions welcome. https://github.com/thomasnield/kotlin_math_cheatsheet/blob/master/README.md
k
Maybe consider using a sequence so there's no intermediary list generated? It's not a big deal for these examples, but maybe it would be significant for large differences between the upper and lower limits?
Copy code
fun main(args: Array<String>) {
  summation(1..3) { it }
  summation(1..5) { 10 * it }
  20.let { n -> summation(0..n) { n * n } }
}

private fun summation(range: IntRange, op: (Int) -> Int) = range.asSequence().map(op).sum()
t
Yeah I'm totally aware of the sequence thing. I didn't want boilerplate to distract from the concept though. I know others are going to point that out so I may make that acknowledgment in the guide.