AK: Add an AK::find helper to return a reference to the found value

This is often more convenient than dealing with iterators.

This commit includes a couple conversions to find_value as examples.
This commit is contained in:
Timothy Flynn 2025-04-05 09:06:51 -04:00 committed by Andreas Kling
parent 9cab5dc0c9
commit 7f37a8f60f
Notes: github-actions[bot] 2025-04-06 11:46:22 +00:00
5 changed files with 34 additions and 30 deletions

View file

@ -901,13 +901,11 @@ static KeyCodeData key_code_data(u32 code_point)
{ 0xE027, {}, UIEvents::KeyCode::Key_Minus, UIEvents::KeyModifier::Mod_Keypad },
});
auto it = find_if(key_code_data.begin(), key_code_data.end(), [&](auto const& data) {
auto data = find_value(key_code_data, [&](auto const& data) {
return data.key == code_point || data.alternate_key == code_point;
});
if (it == key_code_data.end())
return { .key = code_point };
return *it;
return data.value_or({ .key = code_point });
}
// https://w3c.github.io/webdriver/#dfn-shifted-character