Join Slack
`S` is the type of the accumulator (and therefore also the return type).
# getting-started
h
hho
12/19/2018, 12:51 PM
S
is the type of the accumulator (and therefore also the return type).
a
Abdul Kadir
12/19/2018, 1:12 PM
Yeah T is the type passed as the Type in the List but we aren't passing S anywhere
b
blogscot
12/19/2018, 1:14 PM
With
reduce
the accumulator type is determined by the first element of the list being processed. I’ve linked an example:
https://pl.kotl.in/HyrqmCweN
h
hho
12/19/2018, 1:32 PM
You're passing
S
as the type of the first argument in the lambda. This can be any supertype of the collections element type:
https://pl.kotl.in/rk0XOTwx4
👏 1
👆 1
👍 1
a
Abdul Kadir
12/20/2018, 5:16 AM
Thanks a lot:)
Abdul Kadir
12/20/2018, 5:40 AM
I didn't provide any type to the accumulator as the compiler automatically inferred it, that threw me off, now I get it 😅
7
Views
Open in Slack
Previous
Next
kotlinlang
A modern programming language that makes developers happier.
Powered by