Skip to content
Snippets Groups Projects
Commit eb6d8a6a authored by Alexander Rose's avatar Alexander Rose
Browse files

added Table.pick and Table.pickRow helper methods

parent cbbec793
No related branches found
No related tags found
No related merge requests found
......@@ -101,6 +101,14 @@ namespace Table {
return ret as Table<R>;
}
export function pick<S extends R, R extends Schema>(table: Table<S>, schema: R, test: (i: number) => boolean) {
const _view: number[] = []
for (let i = 0, il = table._rowCount; i < il; ++i) {
if (test(i)) _view.push(i)
}
return view(table, schema, _view)
}
export function window<S extends R, R extends Schema>(table: Table<S>, schema: R, start: number, end: number) {
if (start === 0 && end === table._rowCount) return table;
const ret = Object.create(null);
......@@ -194,6 +202,13 @@ namespace Table {
return row;
}
/** Pick the first row for which `test` evaluates to true */
export function pickRow<S extends Schema>(table: Table<S>, test: (i: number) => boolean) {
for (let i = 0, il = table._rowCount; i < il; ++i) {
if (test(i)) return getRow(table, i)
}
}
export function getRows<S extends Schema>(table: Table<S>) {
const ret: Row<S>[] = [];
const { _rowCount: c } = table;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment