|
@@ -549,7 +549,7 @@ $globals.Collection);
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "anyOne",
|
|
|
-protocol: 'adding/removing',
|
|
|
+protocol: 'accessing',
|
|
|
fn: function (){
|
|
|
var self=this;
|
|
|
|
|
@@ -1628,6 +1628,46 @@ messageSends: ["collect:"]
|
|
|
}),
|
|
|
$globals.Collection);
|
|
|
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "single",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+var $1;
|
|
|
+self._ifEmpty_((function(){
|
|
|
+
|
|
|
+return $core.withContext(function($ctx2) {
|
|
|
+
|
|
|
+return self._error_("Collection is empty");
|
|
|
+
|
|
|
+$ctx2.sendIdx["error:"]=1;
|
|
|
+
|
|
|
+
|
|
|
+}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
|
|
|
+
|
|
|
+}));
|
|
|
+$1=$recv(self._size()).__gt((1));
|
|
|
+if($core.assert($1)){
|
|
|
+self._error_("Collection holds more than one element");
|
|
|
+};
|
|
|
+return self._anyOne();
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"single",{},$globals.Collection)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "single\x0a\x09\x22Answer a single element.\x0a\x09Raise an error if collection holds less or more than one element.\x22\x0a\x0a\x09self ifEmpty: [ self error: 'Collection is empty' ].\x0a\x09self size > 1 ifTrue: [ self error: 'Collection holds more than one element' ].\x0a\x09^ self anyOne",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["ifEmpty:", "error:", "ifTrue:", ">", "size", "anyOne"]
|
|
|
+}),
|
|
|
+$globals.Collection);
|
|
|
+
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "size",
|
|
@@ -3866,6 +3906,29 @@ messageSends: ["copyFrom:to:", "-", "size"]
|
|
|
}),
|
|
|
$globals.SequenceableCollection);
|
|
|
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "anyOne",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+return self._at_((1));
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"anyOne",{},$globals.SequenceableCollection)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "anyOne\x0a\x09^ self at: 1",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: ["at:"]
|
|
|
+}),
|
|
|
+$globals.SequenceableCollection);
|
|
|
+
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "atRandom",
|
|
@@ -4431,6 +4494,33 @@ messageSends: ["at:"]
|
|
|
}),
|
|
|
$globals.SequenceableCollection);
|
|
|
|
|
|
+$core.addMethod(
|
|
|
+$core.method({
|
|
|
+selector: "single",
|
|
|
+protocol: 'accessing',
|
|
|
+fn: function (){
|
|
|
+var self=this;
|
|
|
+
|
|
|
+return $core.withContext(function($ctx1) {
|
|
|
+
|
|
|
+
|
|
|
+ if (self.length == 0) throw new Error("Collection is empty");
|
|
|
+ if (self.length > 1) throw new Error("Collection holds more than one element.");
|
|
|
+ return self[0];;
|
|
|
+return self;
|
|
|
+
|
|
|
+}, function($ctx1) {$ctx1.fill(self,"single",{},$globals.SequenceableCollection)});
|
|
|
+
|
|
|
+},
|
|
|
+
|
|
|
+args: [],
|
|
|
+source: "single\x0a<\x0a\x09if (self.length == 0) throw new Error(\x22Collection is empty\x22);\x0a\x09if (self.length >> 1) throw new Error(\x22Collection holds more than one element.\x22);\x0a\x09return self[0];\x0a>",
|
|
|
+referencedClasses: [],
|
|
|
+
|
|
|
+messageSends: []
|
|
|
+}),
|
|
|
+$globals.SequenceableCollection);
|
|
|
+
|
|
|
$core.addMethod(
|
|
|
$core.method({
|
|
|
selector: "stream",
|