or run

npx @tessl/cli init
Log in

Version

Files

docs

function-utilities.mdindex.mdlist-operations.mdmathematical-operations.mdobject-operations.mdstring-processing.md
tile.json

task.mdevals/scenario-3/

Predicate-Sliced Collections

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.

Capabilities

Collect contiguous matches

  • Given [5, 4, 3, 0, 2] and a predicate that checks value > 0, return [5, 4, 3] while ignoring the rest. @test
  • Given [0, 1, 2] and the same predicate, return an empty array because the leading item fails the condition. @test

Drop prefix matches

  • Given [1, 2, -1, 3] and a predicate that checks value > 0, return [-1, 3] after removing only the longest matching prefix. @test

Segment while condition holds

  • Given [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

Split before trigger condition

  • Given [1, 2, 5, 6] and a predicate that checks value >= 5, return [[1, 2], [5, 6]], stopping right before the first triggering element. @test
  • Given [1, 2, 3] and a predicate that never triggers (e.g., value < 0), return [[1, 2, 3], []]. @test

Implementation

@generates

API

export function collectWhile(items, predicate);
export function skipWhile(items, predicate);
export function segmentWhile(items, predicate);
export function splitOnTrigger(items, predicate);

Dependencies { .dependencies }

prelude.ls { .dependency }

Functional utilities that support predicate-driven slicing of lists without mutation.