FIDDLE : https://jsfiddle.net/vktawbzg/
NPM : https://www.npmjs.com/package/linqscript
GITHUB : https://github.com/sevensc/linqscript
En utilisant Typescript, j'ai créé une classe List<T>
qui prolonge Array<T>
l'usage :
var list = new List<ListView>();
...
var selected = list.Items.Where(x => x.Selected);
mise en œuvre :
export class List<T> extends Array<T> {
public Where(callback: (value: T) => boolean, thisArg?: any): List<T> {
try {
const list = new List<T>();
if (this.length <= 0)
return list;
if (typeof callback !== "function")
throw new TypeError(callback + ' is not a function');
for (let i = 0; i < this.length; i++) {
const c = this[i];
if (c === null)
continue;
if (callback.call(thisArg, c))
list.Add(c);
}
return list;
}
catch (ex) {
return new List<T>();
}
}
...
}
EDITAR: J'ai créé un repo sur Github : https://github.com/sevensc/linqscript