Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need IterableExtension<E> with anyIndexed and everyIndexed #238

Open
darkstarx opened this issue Apr 16, 2022 · 1 comment
Open

Need IterableExtension<E> with anyIndexed and everyIndexed #238

darkstarx opened this issue Apr 16, 2022 · 1 comment
Labels
type-enhancement A request for a change that isn't a bug

Comments

@darkstarx
Copy link

darkstarx commented Apr 16, 2022

Could you implement anyIndexed and everyIndexed please?

extension IterableExt<E> on Iterable<E>
{
  bool everyIndexed(final bool Function(int i, E e) test)
  {
    var index = 0;
    for (final element in this) {
      if (!test(index, element)) return false;
    }
    return true;
  }

  bool anyIndexed(final bool Function(int index, E element) test)
  {
    var index = 0;
    for (final element in this) {
      if (test(index, element)) return true;
    }
    return false;
  }
}
@darkstarx darkstarx changed the title ListExtensions needs anyIndexed and everyIndexed Need IterableExtension<E> with anyIndexed and everyIndexed Apr 16, 2022
@osa1 osa1 added the type-enhancement A request for a change that isn't a bug label Apr 20, 2022
@lrhn
Copy link
Member

lrhn commented Jun 13, 2023

There is now an indexed extension getter on Iterable in the platform libraries. You can do someIterable.indexed.any((iv) => indexTest(iv.$1) && valueTest(iv.$2)).

I hope to get better syntax for destructing f directly in the parameter list in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants