← All examples

Queue

list.remove hands the removed element back: no copy, no hole.

queue.zg
# `list.remove` hands the removed element back (decided 2026-09-21): no copy, no hole.

struct Job { name: str.utf8 }
fn run ['job': Job] { std::print.useful["ran ", 'job'.name, newln]; }
MAIN {
    let mut 'queue' := [Job[name = "a"], Job[name = "b"], Job[name = "c"]];
    run[list.remove[lend.mut 'queue', pos 1]];              # straight into a call
    let 'next' := list.remove[lend.mut 'queue', pos 1];     # or kept
    run[give 'next'];
    list.remove[lend.mut 'queue', pos 1];                   # or dropped
    std::print.useful[list.length[lend 'queue'], newln];
}
Output
ran a
ran b
0