lo icon indicating copy to clipboard operation
lo copied to clipboard

[V2] index argument in methods with suffix Indexed

Open dorzepowski opened this issue 11 months ago • 1 comments

Current state: Many methods are accepting iteratee as a function with 2 arguments func(item T, index int)

It's rather often that the index is not needed so the method that could be passed to Map, Filter, Reduce often ends up with with _ int as a second argument, just to match the function struct.

Proposition:

Rename all the current functions which accepts the index to XyzIndexed Add functions without suffix Indexed which accepts similar function but without index argument.

dorzepowski avatar Jan 30 '25 08:01 dorzepowski

From my experience the indexed version is rarely useful in comparison to func (item T). The latter allows you to use the existing function conveniently

lo.Map(foo, bar)

// vs

lo.Map(foo, func(item T, _ int) {
    return bar(item)
}) 

slsyy avatar Apr 11 '25 12:04 slsyy