Skip to content

Add NonEmpty versions of ListUtils #867

@brandon-leapyear

Description

@brandon-leapyear

Could either be done in a new Data.Containers.ListUtils.NonEmpty module or just suffix the functions with NE.

Could either implement all NE functions in terms of non-NE functions:

nubOrd :: Ord a => [a] -> [a]
nubOrd = ...

nubOrdNE :: Ord a => NonEmpty a -> NonEmpty a
nubOrdNE (a :| as) = a :| nubOrd (filter (/= a) as)

or copy the implementations and just implement the lowest NE helper in terms of the non-NE helper:

nubOrd :: Ord a => [a] -> [a]
nubOrd = nubOrdOn id

nubOrdNE :: Ord a => NonEmpty a -> NonEmpty a
nubOrdNE = nubOrdOnNE id

nubOrdOnExcluding :: Ord b => (a -> b) -> Set b -> [a] -> [a]
nubOrdOnExcluding = ...

nubOrdOnExcludingNE :: Ord b => (a -> b) -> Set b -> NonEmpty a -> NonEmpty a
nubOrdOnExcludingNE f s (a :| as) = a :| nubOrdOnExcluding f (Set.insert (f a) s) as

Related: #465

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