MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / splitByContiguousPrefix

Function splitByContiguousPrefix

apps/web/src/lib/utils/splitByContiguousPrefix.ts:10–32  ·  view source on GitHub ↗
(
  items: readonly T[],
  isComplete: (item: T) => boolean
)

Source from the content-addressed store, hash-verified

8 * the predicate are never reordered past items that pass it.
9 */
10export function splitByContiguousPrefix<T>(
11 items: readonly T[],
12 isComplete: (item: T) => boolean
13): { staticItems: T[]; dynamicItems: T[] } {
14 let lastCompleteIndex = -1;
15
16 for (let i = 0; i < items.length; i++) {
17 if (isComplete(items[i])) {
18 if (i === 0 || i === lastCompleteIndex + 1) {
19 lastCompleteIndex = i;
20 } else {
21 break;
22 }
23 } else {
24 break;
25 }
26 }
27
28 return {
29 staticItems: items.slice(0, lastCompleteIndex + 1),
30 dynamicItems: items.slice(lastCompleteIndex + 1),
31 };
32}

Callers 4

atoms.tsFile · 0.90
V1SessionMessagesFunction · 0.90
V2SessionMessagesFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected