Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NonEmpty versions of ListUtils #867

Open
brandon-leapyear opened this issue Nov 7, 2022 · 1 comment
Open

Add NonEmpty versions of ListUtils #867

brandon-leapyear opened this issue Nov 7, 2022 · 1 comment

Comments

@brandon-leapyear
Copy link

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

@treeowl
Copy link
Contributor

treeowl commented Nov 7, 2022

I think a separate module would probably be nicer. What do you think? The second implementation option is definitely the right one.

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

No branches or pull requests

3 participants