The Inbox: Collections-ct.921.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-ct.921.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-ct.921.mcz

==================== Summary ====================

Name: Collections-ct.921
Author: ct
Time: 16 November 2020, 5:22:33.980446 pm
UUID: 848dcc2a-ede6-534c-8244-80f5dd700148
Ancestors: Collections-mt.919

Adds convenience constructor for Dictionary.

Usage:
        Dictionary newFromKeys: 'wasd' values: {0@ -1. -1@0. 0@1. 1@0}

Reuploaded to replace Collections-ct.860, which can be moved into treated inbox. Thanks to everyone for the feedback!

(Ha, it took me less than a year to react on this feedback! Fortunately 2020 was a leap year ... ;-))

=============== Diff against Collections-mt.919 ===============

Item was added:
+ ----- Method: Dictionary class>>newFromKeys:values: (in category 'instance creation') -----
+ newFromKeys: keys values: values
+
+ | dictionary |
+ self assert: [keys size = values size].
+ dictionary := self new: keys size.
+ keys with: values do: [:key :value |
+ dictionary
+ at: key
+ ifPresent: [:ignored | self error: ('Duplicate key "{1}"' format: {key})]
+ ifAbsentPut: [value]].
+ ^ dictionary!