Christoph Thiede uploaded a new version of Collections to project The Inbox: http://source.squeak.org/inbox/Collections-ct.873.mcz
==================== Summary ====================
Name: Collections-ct.873 Author: ct Time: 31 January 2020, 11:53:15.549625 am UUID: 431b3440-c343-7949-b8c4-c5627d640b36 Ancestors: Collections-nice.870
Extends #atLast: protocol on SequenceableCollection by implementing complete ifPresent:Absent: pattern.
See also Collections-ct.872.
=============== Diff against Collections-nice.870 ===============
Item was changed: ----- Method: SequenceableCollection>>atLast:ifAbsent: (in category 'accessing') ----- + atLast: indexFromEnd ifAbsent: aBlock - atLast: indexFromEnd ifAbsent: block - "Return element at indexFromEnd from the last position. - atLast: 1 ifAbsent: [] returns the last element"
+ ^ self + atLast: indexFromEnd + ifPresent: [:element | element] + ifAbsent: aBlock! - ^ self at: self size + 1 - indexFromEnd ifAbsent: block!
Item was added: + ----- Method: SequenceableCollection>>atLast:ifPresent: (in category 'accessing') ----- + atLast: indexFromEnd ifPresent: elementBlock + + ^ self + at: self size + 1 - indexFromEnd + ifPresent: elementBlock + ifAbsent: []!
Item was added: + ----- Method: SequenceableCollection>>atLast:ifPresent:ifAbsent: (in category 'accessing') ----- + atLast: indexFromEnd ifPresent: elementBlock ifAbsent: exceptionBlock + "Answer the value of elementBlock on the element at indexFromEnd from the last position. If the receiver does not contain an element at this position, answer the result of evaluating exceptionBlock." + + ^ self + at: self size + 1 - indexFromEnd + ifPresent: elementBlock + ifAbsent: exceptionBlock!
Now a possible question could be whether we favor deduplication over performance, for example in the #atLast:ifAbsent:. Opinions? :-)
Tests will be added on request.
Best, Christoph ________________________________ Von: Squeak-dev squeak-dev-bounces@lists.squeakfoundation.org im Auftrag von commits@source.squeak.org commits@source.squeak.org Gesendet: Freitag, 31. Januar 2020 11:53:16 An: squeak-dev@lists.squeakfoundation.org Betreff: [squeak-dev] The Inbox: Collections-ct.873.mcz
Christoph Thiede uploaded a new version of Collections to project The Inbox: http://source.squeak.org/inbox/Collections-ct.873.mcz
==================== Summary ====================
Name: Collections-ct.873 Author: ct Time: 31 January 2020, 11:53:15.549625 am UUID: 431b3440-c343-7949-b8c4-c5627d640b36 Ancestors: Collections-nice.870
Extends #atLast: protocol on SequenceableCollection by implementing complete ifPresent:Absent: pattern.
See also Collections-ct.872.
=============== Diff against Collections-nice.870 ===============
Item was changed: ----- Method: SequenceableCollection>>atLast:ifAbsent: (in category 'accessing') ----- + atLast: indexFromEnd ifAbsent: aBlock - atLast: indexFromEnd ifAbsent: block - "Return element at indexFromEnd from the last position. - atLast: 1 ifAbsent: [] returns the last element"
+ ^ self + atLast: indexFromEnd + ifPresent: [:element | element] + ifAbsent: aBlock! - ^ self at: self size + 1 - indexFromEnd ifAbsent: block!
Item was added: + ----- Method: SequenceableCollection>>atLast:ifPresent: (in category 'accessing') ----- + atLast: indexFromEnd ifPresent: elementBlock + + ^ self + at: self size + 1 - indexFromEnd + ifPresent: elementBlock + ifAbsent: []!
Item was added: + ----- Method: SequenceableCollection>>atLast:ifPresent:ifAbsent: (in category 'accessing') ----- + atLast: indexFromEnd ifPresent: elementBlock ifAbsent: exceptionBlock + "Answer the value of elementBlock on the element at indexFromEnd from the last position. If the receiver does not contain an element at this position, answer the result of evaluating exceptionBlock." + + ^ self + at: self size + 1 - indexFromEnd + ifPresent: elementBlock + ifAbsent: exceptionBlock!
squeak-dev@lists.squeakfoundation.org