<div dir="ltr">Hello!<br><br>I attach a change set to add some useful methods to the collections. In particular, missing "ifEmpty" cases, like #sumIfEmpty: or #max:ifEmpty:. I also attach another change set for the CollectionsTests package, to add some tests for these changes.<br><br><div>Here I leave some notes regarding the changes, to help during the review:</div>* For the message #anyOne, the raised exceptions are different now. For example, "(1 to: 0) anyOne" used to raise "subscript is out of bounds: 1", and now raises "this collection is empty" (the same thing happens to "RunArray new anyOne"). I think this is an improvement, although I mention it explicitly just in case.<br>* One case we should validate is with Heap, because "Heap new anyOne" used to return "nil", but now raises "this collection is empty". As the size of the heap is 0 and #isEmpty returns true, I think the change is in the correct direction.<br>* I followed the convention of evaluating "emptyBlockOrValue valueWithPossibleArgument: self" in the empty cases, like Collection>>#ifEmpty: does. This sometimes changes the behavior a bit, by being more permissive. For an interesting case regarding this, see for example the change in #average:ifEmpty:.<div>* I found that Collection>>#max: and #min: skip leading nils. For example: "#(nil 3) max: [:x | x]" answers 3, but "#(3 nil) max: [:x | x]" raises an exception. The code is very explicit about this, so I guess this is (or at some point was) the expected behavior. I left this behavior as it was, but I'm curious if this is something that could be simplified (my expectation would have been for both examples to raise an exception). On the other hand, in case it's needed, it'd be nice to have at least one test documenting it.</div><div>* I left the cases where nil is returned by default as they are (e.g. #detectMax:/#detectMin:), because I'm thinking of this as a change closer to a refactor. But we might consider revisiting those defaults, and make them raise an exception instead, to be consistent with what's done in other cases.</div><br>Cheers!<br>Facu</div>