Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-foundation

Source of release 0.6.1

0.6.1 / src / ak / all_of.lucb

#==============================================================================================
#
#   all_of - whether every element of a range satisfies a predicate
#
#   DESCRIPTION:
#       Port of AK/AllOf.h (lines 1-37), over SimpleIterator ranges and IndexedContainers
#       as find.lucb.
#
#==============================================================================================

# all_of's negated predicate: `[&](auto const& elem) { return !pred(elem); }`, with `pred` as the
# context.
func all_of_negated[T](context: void*?, elem: const T*) -> bool:
    let pred = (const Function1[const T*, bool]*)(context else trap("all_of: no predicate"))
    return not function1_call(pred, elem)

## Ported from AK/AllOf.h:16 AK::all_of.
pub func all_of_tt_iterator[T, TContainer: IndexedContainer[T]](begin: SimpleIterator[TContainer, T], end: SimpleIterator[TContainer, T], predicate: Function1[const T*, bool]) -> bool:
    var captured = predicate
    let negated: func(void*?, const T*) -> bool = all_of_negated
    let found = find_if(begin, end, Function1[const T*, bool](call = negated, context = &captured))
    return not (not simple_iterator_eq(&found, end))

## Ported from AK/AllOf.h:28 AK::all_of.
pub func all_of_t_container[T, TContainer: IndexedContainer[T]](container: TContainer*, predicate: Function1[const T*, bool]) -> bool:
    return all_of_tt_iterator(simple_iterator_begin[TContainer, T](container), simple_iterator_end[T, TContainer](container), predicate)