Skip to content

Add grouping and sorting utilities to NonEmptyVector (parity with NonEmptyList) #27

@webdevred

Description

@webdevred

Description

I am refactoring some of my code to use nonempty-vector instead of NonEmpty lists and noticed that NonEmptyVector currently lacks some of the convenient utility functions available on NonEmptyList, such as groupBy, groupAllWith, and sorting helpers like sort or sortOn.

This makes migration from NonEmptyList to NonEmptyVector less ergonomic, since code that previously relied on these functions must now be rewritten manually using conversions or workarounds.

If others are interested in this feature as well, I would be happy to submit a PR.

Example

xs :: NonEmptyVector Int
xs = unsafeFromList (3 :| [1, 2, 1])

-- desired

NEV.groupBy myPredicate xs
sortOn id xs

-- currently required

NEV.unsafeVector $ groupBy myPredicate (NEV.toVector xs)
NEV.unsafeVector $ sortOn id (NEV.toVector xs)

Proposal

Add the following (or equivalent) functions to NonEmptyVector:

  • groupBy
  • groupAllWith
  • sort
  • sortOn

to achieve feature parity with NonEmptyList.

Motivation

  • Ease migration from NonEmptyList
  • Improve consistency between NonEmpty* data types
  • Avoid unnecessary conversions or loss of non-empty guarantees

Environment

  • Library version: vector-nonempty 0.2.4
  • GHC version: 9.6.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions