Function Subspace :: sus :: iter :: successors

template <class Item, class GenFn>
auto successors(Option<Item> first, GenFn func) -> Successors<Item, GenFn>
requires
sus::fn::FnMut<GenFn, Option<Item> (const Item &)>

Creates a new iterator where each successive item is computed based on the preceding one.

The iterator starts with the given first item (if any) and calls the given FnMutBox<Option<Item>>(const Item&) functor to compute each item's successor.

Example

auto powers_of_10 = sus::iter::successors<u16>(
    sus::some(1_u16), [](const u16& n) { return n.checked_mul(10_u16); });
sus_check(
    sus::move(powers_of_10).collect<Vec<u16>>() ==
    sus::Slice<u16>::from({1_u16, 10_u16, 100_u16, 1000_u16, 10000_u16}));