Posted by
commits-2 on
Jun 10, 2021; 6:41pm
URL: https://forum.world.st/The-Inbox-Collections-ct-947-mcz-tp5130322.html
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.947.mcz==================== Summary ====================
Name: Collections-ct.947
Author: ct
Time: 10 June 2021, 8:40:58.780588 pm
UUID: cb2cdf00-2a3a-5d46-bf15-60255480c1fa
Ancestors: Collections-eem.944
Proposal: Adds sort function that uses a boolean compare block such as [:a :b | a <= b].
Usage examples:
squotVersions sorted: [:a :b | historyWalker shouldVisit: a before: b] asCompareSortFunction.
#(true nil 42) sorted: #compareSafely: asCompareSortFunction.
=============== Diff against Collections-eem.944 ===============
Item was added:
+ ----- Method: BlockClosure>>asCompareSortFunction (in category '*Collections-SortFunctions-converting') -----
+ asCompareSortFunction
+
+ ^ CompareBlockFunction usingBlock: self!
Item was changed:
SortFunction subclass: #CollatorBlockFunction
instanceVariableNames: 'collatorBlock'
classVariableNames: ''
poolDictionaries: ''
category: 'Collections-SortFunctions'!
+ !CollatorBlockFunction commentStamp: 'ct 6/10/2021 20:38' prior: 0!
- !CollatorBlockFunction commentStamp: 'nice 11/5/2017 22:57' prior: 0!
A CollatorBlockFunction is a special SortFunction using a dyadic block to collate objects.
Instance Variables
+ collatorBlock <Block> a dyadic block that must return a -1, 0, or 1.!
- collator <Block> a dyadic block that must return a -1, 0, or 1.!
Item was added:
+ SortFunction subclass: #CompareBlockFunction
+ instanceVariableNames: 'compareBlock'
+ classVariableNames: ''
+ poolDictionaries: ''
+ category: 'Collections-SortFunctions'!
+
+ !CompareBlockFunction commentStamp: 'ct 6/10/2021 20:38' prior: 0!
+ A CompareBlockFunction is a special SortFunction using a dyadic block to compare objects. The default compare logic is the lower-equals function (#<=).
+
+ Instance Variables
+
+ compareBlock <Block> a dyadic block that must return true iff the first argument should not appear after the second , otherwise false.!
Item was added:
+ ----- Method: CompareBlockFunction class>>usingBlock: (in category 'instance creation') -----
+ usingBlock: twoArgsBlock
+
+ ^ self new compareBlock: twoArgsBlock!
Item was added:
+ ----- Method: CompareBlockFunction>>collate:with: (in category 'evaluating') -----
+ collate: anObject with: anotherObject
+
+ ^ (compareBlock value: anObject value: anotherObject)
+ ifTrue: [-1]
+ ifFalse: [1]!
Item was added:
+ ----- Method: CompareBlockFunction>>compareBlock (in category 'accessing') -----
+ compareBlock
+
+ ^ compareBlock!
Item was added:
+ ----- Method: CompareBlockFunction>>compareBlock: (in category 'accessing') -----
+ compareBlock: aBlock
+
+ compareBlock := aBlock.!
Item was added:
+ ----- Method: Symbol>>asCompareSortFunction (in category '*Collections-SortFunctions-converting') -----
+ asCompareSortFunction
+
+ ^ CompareBlockFunction usingBlock: self!