Skip to content

Instantly share code, notes, and snippets.

@ericntd
Created August 15, 2020 13:56
Show Gist options
  • Save ericntd/29cd3c8a52f0d8de1812972e1c3f326e to your computer and use it in GitHub Desktop.
Save ericntd/29cd3c8a52f0d8de1812972e1c3f326e to your computer and use it in GitHub Desktop.
// prepare variable employees which is a list of Employee object
// Same as Task 0
employees.groupingBy { it.department }
.fold(initialValue = 0) { total, employee -> total + employee.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