Skip to content

Commit

Permalink
Merge pull request #355 from herby/gh-354
Browse files Browse the repository at this point in the history
Fixes #354.
  • Loading branch information
NicolasPetton committed Feb 21, 2013
2 parents 37b62d1 + 697779e commit 2b984d3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
13 changes: 13 additions & 0 deletions js/Kernel-Collections.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3366,6 +3366,19 @@ return $1;
}),
smalltalk.Set);

smalltalk.addMethod(
"_collect_",
smalltalk.method({
selector: "collect:",
fn: function (aBlock){
var self=this;
return smalltalk.withContext(function($ctx1) { var $1;
$1=_st(_st(self)._class())._withAll_(_st(self["@elements"])._collect_(aBlock));
return $1;
}, function($ctx1) {$ctx1.fill(self,"collect:",{aBlock:aBlock}, smalltalk.Set)})}
}),
smalltalk.Set);

smalltalk.addMethod(
"_detect_ifNone_",
smalltalk.method({
Expand Down
18 changes: 18 additions & 0 deletions js/Kernel-Collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -4542,6 +4542,24 @@ referencedClasses: []
}),
smalltalk.Set);

smalltalk.addMethod(
"_collect_",
smalltalk.method({
selector: "collect:",
category: 'enumerating',
fn: function (aBlock){
var self=this;
return smalltalk.withContext(function($ctx1) { var $1;
$1=_st(_st(self)._class())._withAll_(_st(self["@elements"])._collect_(aBlock));
return $1;
}, function($ctx1) {$ctx1.fill(self,"collect:",{aBlock:aBlock}, smalltalk.Set)})},
args: ["aBlock"],
source: "collect: aBlock\x0a\x09^self class withAll: (elements collect: aBlock)",
messageSends: ["withAll:", "collect:", "class"],
referencedClasses: []
}),
smalltalk.Set);

smalltalk.addMethod(
"_detect_ifNone_",
smalltalk.method({
Expand Down
13 changes: 13 additions & 0 deletions js/Kernel-Tests.deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2881,6 +2881,19 @@ return self}, function($ctx1) {$ctx1.fill(self,"testAt",{}, smalltalk.SetTest)})
}),
smalltalk.SetTest);

smalltalk.addMethod(
"_testCollect",
smalltalk.method({
selector: "testCollect",
fn: function (){
var self=this;
return smalltalk.withContext(function($ctx1) { _st(self)._assert_equals_([(0), (2)],_st(_st(_st(_st([(5), (6), (8)])._asSet())._collect_((function(x){
return smalltalk.withContext(function($ctx2) {return _st(x).__backslash_backslash((3));
}, function($ctx2) {$ctx2.fillBlock({x:x},$ctx1)})})))._asArray())._sorted());
return self}, function($ctx1) {$ctx1.fill(self,"testCollect",{}, smalltalk.SetTest)})}
}),
smalltalk.SetTest);

smalltalk.addMethod(
"_testPrintString",
smalltalk.method({
Expand Down
18 changes: 18 additions & 0 deletions js/Kernel-Tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -3712,6 +3712,24 @@ referencedClasses: ["Set", "Error"]
}),
smalltalk.SetTest);

smalltalk.addMethod(
"_testCollect",
smalltalk.method({
selector: "testCollect",
category: 'tests',
fn: function (){
var self=this;
return smalltalk.withContext(function($ctx1) { _st(self)._assert_equals_([(0), (2)],_st(_st(_st(_st([(5), (6), (8)])._asSet())._collect_((function(x){
return smalltalk.withContext(function($ctx2) {return _st(x).__backslash_backslash((3));
}, function($ctx2) {$ctx2.fillBlock({x:x},$ctx1)})})))._asArray())._sorted());
return self}, function($ctx1) {$ctx1.fill(self,"testCollect",{}, smalltalk.SetTest)})},
args: [],
source: "testCollect\x0a\x09self assert: #(0 2) equals: (#(5 6 8) asSet collect: [ :x | x \x5c\x5c 3 ]) asArray sorted",
messageSends: ["assert:equals:", "sorted", "asArray", "collect:", "\x5c\x5c", "asSet"],
referencedClasses: []
}),
smalltalk.SetTest);

smalltalk.addMethod(
"_testPrintString",
smalltalk.method({
Expand Down
4 changes: 4 additions & 0 deletions st/Kernel-Collections.st
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,10 @@ asArray

!Set methodsFor: 'enumerating'!

collect: aBlock
^self class withAll: (elements collect: aBlock)
!

detect: aBlock ifNone: anotherBlock
^elements detect: aBlock ifNone: anotherBlock
!
Expand Down
4 changes: 4 additions & 0 deletions st/Kernel-Tests.st
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,10 @@ testAt
self should: [Set new at: 1 put: 2] raise: Error
!

testCollect
self assert: #(0 2) equals: (#(5 6 8) asSet collect: [ :x | x \\ 3 ]) asArray sorted
!

testPrintString
| set |
set := Set new.
Expand Down

0 comments on commit 2b984d3

Please sign in to comment.