fun funcSum2(funcs: List<() -> Int>): Int =
funcs.sumOf { it() }
Function Call | Return Value | |||
---|---|---|---|---|
funcSum2(listOf({ 5 }, { 3 })) | → | |||
funcSum2(listOf({ 8 }, { 6 }, { 11 })) | → | |||
funcSum2(listOf({ 1 }, { 2 }, { 3 }, { 4 })) | → | |||
funcSum2(listOf({ 9 }, { 9 })) | → |
Experiment with this code on Gitpod.io or as a Kotlin Playground