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

Spec: about index argument in iteratee #579

Open
samber opened this issue Jan 25, 2025 · 1 comment
Open

Spec: about index argument in iteratee #579

samber opened this issue Jan 25, 2025 · 1 comment
Labels

Comments

@samber
Copy link
Owner

samber commented Jan 25, 2025

Go does not support optional arguments. We have to duplicate helpers if we want to make the index int argument optional.

I'm opening this issue to discuss a new standard for naming helpers.

  • lo.Map(list, func(item T) U -> no index
  • lo.MapI(list, func(item T, index int) U -> index

The I suffix might not be comprehensible. I would suggest WithIndex as second choice.

It might introduce a large breaking change because Map and Filter are concerned. (see discussion about v2: #578)

Also, I wonder what would be the best type for this index:

  • int is simple
  • int64 for larger collections (useless 99.9% of time)
  • uint64 the most accurate type

Don't forget that passing a function to a helpers is a very developer-friendly API: lo.Map(collection, aFunc). Since int is the most used type it seems valuable to avoid any exotic typing and cast.

Linking issues & PR: #565

@quantumsheep
Copy link
Contributor

Also, I wonder what would be the best type for this index

int is the one used to identify slices index. The others would mean applying a manual conversion.

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

No branches or pull requests

2 participants