Skip to content

Instantly share code, notes, and snippets.

@Nublo
Created October 7, 2018 14:49
Show Gist options
  • Save Nublo/035624ffd95b3916f5be39b98202eb56 to your computer and use it in GitHub Desktop.
Save Nublo/035624ffd95b3916f5be39b98202eb56 to your computer and use it in GitHub Desktop.
fun sum(xs: List<Int>): Int = when (xs.size) {
0 -> 0
else -> {
val head = xs.head
val tailSum = sum(xs.tail)
head + tailSum
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment