Skip to content

add Iter::with_numbering(start~: Int) #1866

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

Open
hackwaly opened this issue Apr 2, 2025 · 7 comments
Open

add Iter::with_numbering(start~: Int) #1866

hackwaly opened this issue Apr 2, 2025 · 7 comments

Comments

@hackwaly
Copy link
Contributor

hackwaly commented Apr 2, 2025

Maybe zip_with_numbering better?

@illusory0x0
Copy link
Contributor

Maybe zip_with_numbering better?

I think with_index would be better.

fn Iter::with_index[A](self : Iter[A]) -> Iter2[Int,A]

@peter-jerry-ye
Copy link
Collaborator

What about mapi and eachi?

@hackwaly
Copy link
Contributor Author

hackwaly commented Apr 11, 2025

mapi cannot fit my need.

Iter::zip_with_numbering[T](start~: Int = 0) -> Iter[(T, Int)]

@peter-jerry-ye
Copy link
Collaborator

peter-jerry-ye commented Apr 11, 2025

Isn't that just a.mapi(fn (index, value) { (value, index + start) } )?

@hackwaly
Copy link
Contributor Author

Yes, you are right. But you can derive mapi like this a. zip_with_numbering().map(fn { (v, i) => ... }).

@hackwaly hackwaly reopened this Apr 11, 2025
@illusory0x0
Copy link
Contributor

use Iter2 we can use for syntaxto iterate index and element, and then use break statement, which eachi cann't do.

use Iter2 can avoid destruct pair, use mapi has to construct pair and destruct pair

@peter-jerry-ye
Copy link
Collaborator

  1. [Feature Request] impl Iter2 for Iter[(A, B)] #1319
  2. the construct pair and destruct pair should be some optimization considered at compiler level

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants