Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #354. #355

Merged
merged 1 commit into from Feb 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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