|
@@ -1749,6 +1749,7 @@ var self=this;
|
|
|
var dict;
|
|
|
return smalltalk.withContext(function($ctx1) {
|
|
|
var $1;
|
|
|
+_st(self)._deprecatedAPI();
|
|
|
dict=_st(self)._new();
|
|
|
_st(aCollection)._do_((function(each){
|
|
|
return smalltalk.withContext(function($ctx2) {
|
|
@@ -1758,12 +1759,65 @@ $1=dict;
|
|
|
return $1;
|
|
|
}, function($ctx1) {$ctx1.fill(self,"fromPairs:",{aCollection:aCollection,dict:dict},smalltalk.HashedCollection.klass)})},
|
|
|
args: ["aCollection"],
|
|
|
-source: "fromPairs: aCollection\x0a\x09| dict |\x0a\x09dict := self new.\x0a\x09aCollection do: [:each | dict add: each].\x0a\x09^dict",
|
|
|
+source: "fromPairs: aCollection\x0a\x09\x22This message is poorly named and has been replaced by #newFrom:\x22\x0a\x09| dict |\x0a\x09self deprecatedAPI.\x0a\x09dict := self new.\x0a\x09aCollection do: [:each | dict add: each].\x0a\x09^dict",
|
|
|
+messageSends: ["deprecatedAPI", "new", "do:", "add:"],
|
|
|
+referencedClasses: []
|
|
|
+}),
|
|
|
+smalltalk.HashedCollection.klass);
|
|
|
+
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "newFrom:",
|
|
|
+category: 'instance creation',
|
|
|
+fn: function (aCollection){
|
|
|
+var self=this;
|
|
|
+var newCollection;
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1;
|
|
|
+newCollection=_st(self)._new();
|
|
|
+_st(aCollection)._do_((function(each){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+return _st(newCollection)._add_(each);
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
|
|
|
+$1=newCollection;
|
|
|
+return $1;
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"newFrom:",{aCollection:aCollection,newCollection:newCollection},smalltalk.HashedCollection.klass)})},
|
|
|
+args: ["aCollection"],
|
|
|
+source: "newFrom: aCollection\x0a| newCollection |\x0anewCollection := self new.\x0aaCollection do: [:each | newCollection add: each].\x0a^ newCollection.",
|
|
|
messageSends: ["new", "do:", "add:"],
|
|
|
referencedClasses: []
|
|
|
}),
|
|
|
smalltalk.HashedCollection.klass);
|
|
|
|
|
|
+smalltalk.addMethod(
|
|
|
+smalltalk.method({
|
|
|
+selector: "newFromPairs:",
|
|
|
+category: 'instance creation',
|
|
|
+fn: function (aCollection){
|
|
|
+var self=this;
|
|
|
+var newCollection;
|
|
|
+function $Error(){return smalltalk.Error||(typeof Error=="undefined"?nil:Error)}
|
|
|
+return smalltalk.withContext(function($ctx1) {
|
|
|
+var $1,$2;
|
|
|
+$1=_st(_st(aCollection)._size())._even();
|
|
|
+if(! smalltalk.assert($1)){
|
|
|
+_st($Error())._signal_("#newFromPairs only accepts arrays of an even length");
|
|
|
+};
|
|
|
+newCollection=_st(self)._new();
|
|
|
+_st(_st((1))._to_by_(_st(aCollection)._size(),(2)))._do_((function(keyIndex){
|
|
|
+return smalltalk.withContext(function($ctx2) {
|
|
|
+return _st(newCollection)._at_put_(_st(aCollection)._at_(keyIndex),_st(aCollection)._at_(_st(keyIndex).__plus((1))));
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({keyIndex:keyIndex},$ctx1)})}));
|
|
|
+$2=newCollection;
|
|
|
+return $2;
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"newFromPairs:",{aCollection:aCollection,newCollection:newCollection},smalltalk.HashedCollection.klass)})},
|
|
|
+args: ["aCollection"],
|
|
|
+source: "newFromPairs: aCollection\x0a\x22Accept an array of elements where every two elements form an association - the odd element being the key, and the even element the value.\x22\x0a| newCollection |\x0aaCollection size even ifFalse: [ Error signal: '#newFromPairs only accepts arrays of an even length' ].\x0anewCollection := self new.\x0a( 1 to: aCollection size by: 2 ) do: [ :keyIndex | newCollection at: ( aCollection at: keyIndex ) put: ( aCollection at: keyIndex + 1 ) ].\x0a^ newCollection.",
|
|
|
+messageSends: ["ifFalse:", "signal:", "even", "size", "new", "do:", "at:put:", "at:", "+", "to:by:"],
|
|
|
+referencedClasses: ["Error"]
|
|
|
+}),
|
|
|
+smalltalk.HashedCollection.klass);
|
|
|
+
|
|
|
|
|
|
smalltalk.addClass('Dictionary', smalltalk.HashedCollection, ['keys', 'values'], 'Kernel-Collections');
|
|
|
smalltalk.Dictionary.comment="I represent a set of elements that can be viewed from one of two perspectives: a set of associations,\x0aor a container of values that are externally named where the name can be any object that responds to `=`.\x0a\x0aThe external name is referred to as the key.";
|