Skip to content

Commit 5b83d48

Browse files
authoredDec 7, 2019
Update sorting documentation to Pharo 8
Fixes #211
1 parent f671bcc commit 5b83d48

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎General/SortingCollections.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Those two methods also have an equivalent without argument, `#sort` and `#sorted
2929
The API described here will sort a collection at one point but new elements added to the collection will not be sorted. If you wish to keep a collection sorted, you should use `SortedCollection` as explained in the next section.
3030

3131
> Warning: If not absolutely needed, one should not use `SortedCollection` because it might impact performances of your software when adding and removing items to the collection.
32+
3233
### Keep a collection sorted
3334

3435
In case you want to keep a collection sorted, you should use a `SortedCollection`. This collection is configured with a sort block or sort function and will sort all new elements added to the collection.
@@ -44,11 +45,18 @@ You can transform a collection into sorted collection using `#asSortedCollection
4445
You can also instantiate yourself the sorted collection:
4546

4647
```Smalltalk
47-
(SortedCollection sortBlock: #yourself ascending)
48+
(SortedCollection sortUsing: #yourself ascending)
49+
addAll: #(1 2 4 7 3 6 4);
50+
yourself "a SortedCollection(1 2 3 4 4 6 7)"
51+
```
52+
53+
```Smalltalk
54+
(SortedCollection sortBlock: [ :a :b | a < b ])
4855
addAll: #(1 2 4 7 3 6 4);
4956
yourself "a SortedCollection(1 2 3 4 4 6 7)"
5057
```
5158

59+
> Note: #sortUsing: was introduced in Pharo 8. In previous versions it is possible to use #sortBlock: for both sort block and sort functions.
5260
5361
## Sort functions
5462

0 commit comments

Comments
 (0)
Please sign in to comment.