supermarin / ObjectiveSugar

ObjectiveC additions for humans. Ruby style.
MIT License
2.17k stars 190 forks source link

-[NSArray reduce:withBlock:] implementation is incorrect #119

Open soxjke opened 7 years ago

soxjke commented 7 years ago

When initial value is set to nil and the array consists of single item, this item is returned and reduce block is never evaluated.

There seems to be an issue at https://github.com/supermarin/ObjectiveSugar/blob/master/Classes/NSArray%2BObjectiveSugar.m#L178

I would rather write it as

accumulator = block(accumulator, object);

Does this make sense?