added internal naive (recursive) version of CROSSPRODUCT

pull/95/head
jmoenig 2021-02-08 11:37:08 +01:00
rodzic daf9dd474f
commit 0486733aca
2 zmienionych plików z 16 dodań i 0 usunięć

Wyświetl plik

@ -11,6 +11,7 @@
### 2021-02-06
* lists, objects, threads: new RESHAPE primitive
* lists: added internal naive (recursive) version of CROSSPRODUCT
### 2021-02-06
* simplified private list.range() method

Wyświetl plik

@ -122,6 +122,7 @@ var ListWatcherMorph;
ravel() - answer a flat list of all atoms in all sublists
transpose() - answer a 2D list with rows turned into columns
reshape() - answer a new list formatted to the given dimensions.
crossproduct() - answer a new list of all possible sublist tuples
query() - answer a part of a list or multidimensionel struct
*/
@ -642,6 +643,20 @@ List.prototype.asChunksOf = function (size) {
return trg;
};
List.prototype.crossproduct = function () {
// expects myself to be a list of lists.
// answers a new list of all possible tuples
// with one item from each of my sublists
if (this.isEmpty()) {
return new List([new List()]);
}
return this.at(1).map(
first => this.cdr().crossproduct().map(
each => this.cons(first, each)
)
).flatten();
};
// List conversion:
List.prototype.asArray = function () {