MCPcopy Create free account
hub / github.com/TanStack/db / takeFromStart

Method takeFromStart

packages/db/src/indexes/basic-index.ts:425–439  ·  view source on GitHub ↗

* Returns the first n items in sorted order (from the start)

(n: number, filterFn?: (key: TKey) => boolean)

Source from the content-addressed store, hash-verified

423 * Returns the first n items in sorted order (from the start)
424 */
425 takeFromStart(n: number, filterFn?: (key: TKey) => boolean): Array<TKey> {
426 const result: Array<TKey> = []
427 for (let i = 0; i < this.sortedValues.length && result.length < n; i++) {
428 const keys = this.valueMap.get(this.sortedValues[i])
429 if (keys) {
430 for (const key of keys) {
431 if (result.length >= n) break
432 if (!filterFn || filterFn(key)) {
433 result.push(key)
434 }
435 }
436 }
437 }
438 return result
439 }
440
441 /**
442 * Returns the first n items in reverse sorted order (from the end)

Calls 2

filterFnFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected