1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-07 21:17:07 +09:00

AK: Implement {first|last}_matching for Span

This commit is contained in:
stelar7 2025-05-02 14:28:37 +02:00 committed by Jelle Raaijmakers
parent 0890b10d11
commit 93d7a29306
Notes: github-actions[bot] 2025-05-06 09:18:26 +00:00

View file

@ -306,6 +306,28 @@ public:
{
return { data(), size() };
}
template<typename TUnaryPredicate>
Optional<T&> last_matching(TUnaryPredicate const& predicate)
{
for (ssize_t i = size() - 1; i >= 0; --i) {
if (predicate(at(i))) {
return at(i);
}
}
return {};
}
template<typename TUnaryPredicate>
Optional<T&> first_matching(TUnaryPredicate const& predicate)
{
for (size_t i = 0; i < size(); ++i) {
if (predicate(at(i))) {
return at(i);
}
}
return {};
}
};
template<typename T>