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

Extension .loop or .cycle method or getter #250

Open
FMorschel opened this issue Oct 4, 2022 · 0 comments
Open

Extension .loop or .cycle method or getter #250

FMorschel opened this issue Oct 4, 2022 · 0 comments

Comments

@FMorschel
Copy link

FMorschel commented Oct 4, 2022

I think there could be a getter/method that iterates through a list looping/cycling through its elements. My use case was cycling through the items on a String.split(pattern) so I could join them again in different orders.

Implementation

final list = ['A', 'B', 'C'];

for (int i = 0; i < list.length; i++) {
  final result = [ ...list.sublist(i), ...list.take(i)];
  print('$result');
}

Output

[A, B, C]
[B, C, A]
[C, A, B]
@FMorschel FMorschel changed the title Extension .loop method or getter Extension .loop or .cycle method or getter Oct 24, 2022
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