class QueryArray {
static from(elements) {
return new this(elements);
}
constructor(elements) {
this.elements = elements;
}
map(mapFct) {
let newElements = Array.newDynamic();
for (let nextElem of this.elements) {
let newElem = mapFct(nextElem);
newElements.add(newElem);
}
return QueryArray.from(newElements);
}
forEach(actionFct) {
for (let nextElem of this.elements)
actionFct(nextElem);
}
findFirst(matchFct) {
let elements = this.elements;
for (let i = 0; i < elements.length; i++) {
let nextElem = elements.get(i);
if (matchFct(nextElem))
return i;
}
return -1;
}
toString() {
return this.elements.toString();
}
printAll(label) {
println(label);
this.forEach(nextElem => println(nextElem.toString()));
}
} _br_ _br_
let array = Mathematician.newSampleSet1();
let qarray = QueryArray.from(array);
qarray.forEach (next => println(next.toString()));
Copy It...
Try It...