android - Kotlin reduce function for 2d list not working -
i need total size of 2d list. implementation:
fun totalsize(parts: list<list<string>>): int { return parts.reduce { total, next -> total + next.size } }
i type inference fail. required int, got list. next.size should return int.
better: map operation during sum (from @ruckus t-boom comment)
parts.sumby { it.size }
original: map inner lists sizes first (guessing kotlin syntax):
parts.map { l -> l.size }.reduce { total, -> total + }
Comments
Post a Comment