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-1/

Segmented Queue Composer

Compose a single, ordered queue from nested sections with configurable trimming and end-of-queue reversal. All operations must be immutable, leaving the provided arrays unchanged.

Capabilities

Section trimming and flattening

Trim each section by dropping the first drop items (default: 0) and, if take is provided, keeping only the first take items of what remains. The processed sections are concatenated in their original order into a flat queue.

  • Given [[1, 2, 3], [4, 5], [6, 7, 8]] with { drop: 1, take: 2 }, the composed queue is [2, 3, 5, 7, 8], leaving the original sections unchanged. @test

Tail reversal

After flattening, if reverseTailCount is provided and greater than zero, reverse only the final reverseTailCount items of the queue, preserving the order of earlier items.

  • Given [[1, 2], [3, 4, 5]] with { reverseTailCount: 3 }, the composed queue is [1, 2, 5, 4, 3]. @test

Pivot split

Expose a helper that splits any composed queue at a pivot index into [before, after], where before contains elements up to but not including the pivot position.

  • Splitting [10, 20, 30, 40, 50] at pivot 3 returns [[10, 20, 30], [40, 50]]. @test

Implementation

@generates

API

export type ComposeOptions = {
  drop?: number,
  take?: number,
  reverseTailCount?: number,
};

/**
 * Builds a queue from nested sections without mutating inputs.
 */
export function composeQueue(
  sections: Array<Array<any>>,
  options?: ComposeOptions
): Array<any>;

/**
 * Splits a queue at the given pivot index into [before, after].
 */
export function splitQueue(
  queue: Array<any>,
  pivotIndex: number
): [Array<any>, Array<any>];

Dependencies { .dependencies }

prelude-ls { .dependency }

Functional list utilities for slicing, concatenation, mapping over lists, and flattening nested collections.