https://kotlinlang.org logo
#getting-started
Title
# getting-started
d

Daniele B

09/03/2020, 8:45 PM
so, if:
Copy code
val obj1 = MyDataObj(1,3,4)
val obj2 = MyDataObj(3,2,3)
val obj3 = MyDataObj(2,4,1)
val list = listof(obj1,obj2,obj3)
I would like to derive
objTot
, which has a=6, b=9, c=8
c

Casey Brooks

09/03/2020, 8:49 PM
Or
reduce
to use the first object in the list as the starting accumulator, instead of manually specifying one. https://pl.kotl.in/JFktqNpTr
Semantically,
reduce
is for when you are “collapsing” values into a single object of the same type as the originals.
fold
is when you’re collapsing those values into a different type, or you want to manually specify the starting state for accumulation
d

Daniele B

09/03/2020, 9:02 PM
great! thank you