prx 0.6.1

Praxis — agent-native Unix tools. Single binary replacing grep, cat, find, sed, diff for AI coding agents.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/// Retain items from `vec` while their cumulative cost stays within `budget`.
/// Returns the total cost of retained items.
pub fn retain_within<T>(vec: &mut Vec<T>, budget: usize, cost_fn: impl Fn(&T) -> usize) -> usize {
    let mut used = 0;
    vec.retain(|item| {
        let cost = cost_fn(item);
        if used + cost <= budget {
            used += cost;
            true
        } else {
            false
        }
    });
    used
}