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

LazyList should implement RandomAccess #624

Open
Miha-x64 opened this issue Mar 26, 2017 · 0 comments
Open

LazyList should implement RandomAccess #624

Miha-x64 opened this issue Mar 26, 2017 · 0 comments

Comments

@Miha-x64
Copy link

Miha-x64 commented Mar 26, 2017

Positional access in LazyList is as fast as sequential, positional for-each (for (int i = 0; i < size; i++)) is as fast as iterator for-each (for (E e : list)), and thus this class should implement java.util.RandomAccess.

I use positional for-each with RandomAccess lists heavily, e. g. (Kotlin)

inline fun <T, L> L.forEach(action: (T) -> Unit): Unit
        where L : List<T>, L : RandomAccess {
    for (i in 0 until size)  action(this[i])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant