Skip to content

Add index argument to partition predicate #1557

Closed

Description

@T3sT3ro

It would be nice to have an index argument for the partition predicate, to make the API more similar to the already existing array functions like map, filter, reduce and others.

For example:

const [odds, evens] = partition(foo, (x, i) => i % 2 === 1);

Activity

  1. T3sT3ro commented on Dec 16, 2025

    @T3sT3ro
    ContributorAuthor

    While at it I noticed several other functions that operate on arrays could use the index as well. For starters it would be worth to take a look at the array utils.

  2. T3sT3ro commented on Dec 16, 2025

    @T3sT3ro
    ContributorAuthor

    Following the logic of "least surprise", what do you think that the array functions resembled the regular array function's signature as closely with all 3 parameters — value, index and array?

    map(
       callbackfn: (value: T, index: number, array: readonly T[]) => unknown, 
       thisArg?: any
    ): unknown[]
  3. raon0211 commented on Dec 18, 2025

    @raon0211
    Collaborator

    As you mentioned, I think there should be three arguments (value, index, and the original array) given to array functions.

  4. T3sT3ro commented on Dec 18, 2025

    @T3sT3ro
    ContributorAuthor

    In that case I can go over array functions and update their callback functions. Should I also do so for the lodash compat functions, or leave them as is?

  5. 6 remaining items

  6. raon0211 commented on Jan 15, 2026

    @raon0211
    Collaborator

    For lodash-compatible functions, we actually want to preserve lodash's original behavior—so no changes needed here. Thanks for helping out though!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions