simc / dartx

Superpowers for Dart. Collection of useful static extension methods.
https://pub.dev/packages/dartx
Apache License 2.0
1.09k stars 87 forks source link

Linear complexity of elementAt #124

Closed RomanKornev closed 3 years ago

RomanKornev commented 3 years ago

Is there a reason why elementAt needs to go through every item one by one? I suggest instead to check for bounds and access by index directly. https://github.com/leisim/dartx/blob/master/lib/src/iterable.dart#L43

passsy commented 3 years ago

Thanks for reporting. While it is not possible for Iterable, there is the opportunity to add a faster version for List

RomanKornev commented 3 years ago

Thanks! I think elementAtOrElse might have the same problem.