In `Iterable.reduce`, why is `T` constrained to be...
# announcements
n
In
Iterable.reduce
, why is
T
constrained to be a subtype of
S
? As long as
operation
produces the correct type, what is the problem?
Copy code
public inline fun <S, T : S> Iterable<T>.reduce(operation: (acc: S, T) -> S): S
d
The initial value of
acc
is the first element, so the elements of the Iterable need to fit into
S
.
👍 1
s
You want
fold
👍 2