Skip to content

Spec: about index argument in iteratee #579

@samber

Description

@samber

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions