Browse Source

Array >> allIn:.

#(3 4) allIn: [ :a :b | a + b ] ==> 7
Herby Vojčík 4 years ago
parent
commit
34d99ac6b3
3 changed files with 42 additions and 0 deletions
  1. 2 0
      lang/API-CHANGES.txt
  2. 34 0
      lang/src/Kernel-Collections.js
  3. 6 0
      lang/src/Kernel-Collections.st

+ 2 - 0
lang/API-CHANGES.txt

@@ -5,6 +5,8 @@
 * Lots of changes in Compiler.
 * Added Teachable class.
 
++ Array >>
+  + allIn:
 + Behavior >>
   + alternateConstructorViaSelector:
   + applySuperConstructorOn:withArguments:

+ 34 - 0
lang/src/Kernel-Collections.js

@@ -4465,6 +4465,40 @@ return self;
 }; }),
 $globals.Array);
 
+$core.addMethod(
+$core.method({
+selector: "allIn:",
+protocol: "enumerating",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aBlock"],
+source: "allIn: aBlock\x0a\x09^ aBlock valueWithPossibleArguments:\x0a\x09\x09\x22collect to match #in: behaviour\x22\x0a\x09\x09(self collect: [ :each | each in: [ :x | x ] ])",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["valueWithPossibleArguments:", "collect:", "in:"]
+}, function ($methodClass){ return function (aBlock){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(aBlock)._valueWithPossibleArguments_($self._collect_((function(each){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+return $recv(each)._in_((function(x){
+return x;
+
+}));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
+//>>excludeEnd("ctx");
+})));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"allIn:",{aBlock:aBlock})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.Array);
+
 $core.addMethod(
 $core.method({
 selector: "asJavaScriptSource",

+ 6 - 0
lang/src/Kernel-Collections.st

@@ -1131,6 +1131,12 @@ shallowCopy
 
 !Array methodsFor: 'enumerating'!
 
+allIn: aBlock
+	^ aBlock valueWithPossibleArguments:
+		"collect to match #in: behaviour"
+		(self collect: [ :each | each in: [ :x | x ] ])
+!
+
 collect: aBlock
 	"Optimized version"