nonempty-vector icon indicating copy to clipboard operation
nonempty-vector copied to clipboard

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

Open webdevred opened this issue 2 months ago • 6 comments

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

webdevred avatar Nov 07 '25 23:11 webdevred