agent: builder model: sonnet max_turns: 70 budget_usd: 12 effort: low —

Brief: #1130, drain() on BTreeMap, HashSet and BTreeSet (ADR-386)

Blocks: none (repays C1b’s clone in ledger_items_stored; C1c also edits ledger_items.nika: if its commit is on develop, add beside it, do not reorder)

Score: std counterpart decided by the architect (ADR-386), self-hosting debt (a clone written round a missing form). Small: one ledger form known (HashMap::drain), effort low.

Issue #1130

drain() on BTreeMap, HashSet and BTreeSet (ADR-386, architect’s decision 2026-11-01). Only Vec::drain and collections::HashMap::drain are in std.contracts (:2971, :2982); C1b (547e6462) had to clone every set out of a borrowed BTreeMap for want of it.

Probe (target/fast/nikaia at e1a88e49):

use std::collections
fn main() {
    let mut m: collections::BTreeMap[String, Vec[i64]] = collections::BTreeMap()
    m.insert("a", [1, 2])
    for (k, v) in m.drain() {
        print(f"{k} {v.len()}\n")
    }
}

NK1171: collections::BTreeMap has no method called drain. Expected: a 2.

Facts: Where things live, Traps already met, Commands

Locations

To build

  1. The three ledger entries and their lowering; test tests/compiler/tests/drain_every_map_and_set.nika (+ .stdout): a BTreeMap drained in key order with each value handed to a Vec that keeps it, a HashSet drained into a sum, a BTreeSet drained in order, and a BTreeMap field of a let mut struct drained and then len() 0. Fails on the unfixed binary (NK1171), passes --both-settings.
  2. Repay C1b’s clone: ledger_items_stored (crates/nikaia-std/src/tools/ledger_items.nika:488) takes each unit’s map over with for (key, code) in unit.drain() and extend(code.resolved) / extend(code.free) with no .iter().cloned(); contracts/mod.rs:444’s caller keeps passing owned maps (adapt to what the lowering asks). lower-std, its fixpoint, cargo test -p nikaia --lib contracts::, --test it -- throws ledger contract.

Rules

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/bugs/b32-1130-drain-every-map.md.report.md)

Fields of docs/architect.md, Briefs and reports: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Owner (a question for the owner), Disk freed, for a move Rs2nika: (the kept N of M lines of rs2nika --score and the three costliest hand edits, else none), and last Attribution: with your commit trailer lines below it.

This site is open source. Improve this page.