Skip to content

Instantly share code, notes, and snippets.

@ericntd
Created July 6, 2020 02:46
Show Gist options
  • Save ericntd/efd40f99f579a84ca56ee222ccf650de to your computer and use it in GitHub Desktop.
Save ericntd/efd40f99f579a84ca56ee222ccf650de to your computer and use it in GitHub Desktop.
employees.groupingBy { it.department }
.aggregate { key, acc: Int?, element, isFirstElement ->
return@aggregate if (isFirstElement) {
0 + element.salary
} else {
acc!! + element.salary
}
}
.map {
println("Total salary for department ${it.key} is ${it.value}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment