docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Implement a small utility module that exposes pure helpers for carving arrays into prefixes and suffixes based on boolean predicates. Each helper should accept a predicate of the form (item, index) => boolean, leave the original array untouched, and return new arrays describing the requested slice.
[5, 4, 3, 0, 2] and a predicate that checks value > 0, return [5, 4, 3] while ignoring the rest. @test[0, 1, 2] and the same predicate, return an empty array because the leading item fails the condition. @test[1, 2, -1, 3] and a predicate that checks value > 0, return [-1, 3] after removing only the longest matching prefix. @test[2, 4, 6, 7, 8] and a predicate that checks for even numbers, return [[2, 4, 6], [7, 8]] where the first entry captures the contiguous matches and the second contains the remainder. @test[1, 2, 5, 6] and a predicate that checks value >= 5, return [[1, 2], [5, 6]], stopping right before the first triggering element. @test[1, 2, 3] and a predicate that never triggers (e.g., value < 0), return [[1, 2, 3], []]. @testexport function collectWhile(items, predicate);
export function skipWhile(items, predicate);
export function segmentWhile(items, predicate);
export function splitOnTrigger(items, predicate);Functional utilities that support predicate-driven slicing of lists without mutation.