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

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -