Skip to content

Instantly share code, notes, and snippets.

@Nublo
Created October 7, 2018 14:56
Show Gist options
  • Save Nublo/f7f3f2c046396de79d1d63b00bc0ab88 to your computer and use it in GitHub Desktop.
Save Nublo/f7f3f2c046396de79d1d63b00bc0ab88 to your computer and use it in GitHub Desktop.
fun <T, R> reduce(s: T, xs: List<R>, f: (T, R) -> T): T = when (xs.size) {
0 -> s
else -> reduce(f(s, xs.head), xs.tail, f)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment