Exercise 04 / 24: Who's on call?

// Iterators of Code 2026 — Day 04: Who's on call?
// Refactor first_available using iterators. Return the first available engineer,
// not the last; return None if nobody can help. Borrow the name from the roster.

fn first_available<'a>(roster: &[(&'a str, bool)]) -> Option<&'a str> {
    let mut answer = None;
    for &(name, available) in roster {
        if available {
            answer = Some(name);
            break;
        }
    }
    answer
}

fn main() {
    assert_eq!(
        first_available(&[("Ada", false), ("Lin", true), ("Sam", true)]),
        Some("Lin")
    );
    assert_eq!(first_available(&[("Ada", false)]), None);
    assert_eq!(first_available(&[]), None);
}

Your solution

Standalone .rs / std only. Stored, not executed.

60 characters max. Not a login.

File overrides pasted code.

Maximum solution size: 64 KiB.

Editing access uses this browser's cookie. Clearing cookies loses access.