Skip to content

Add variants of split #387

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

Closed
nomeata opened this issue Jan 31, 2017 · 4 comments
Closed

Add variants of split #387

nomeata opened this issue Jan 31, 2017 · 4 comments

Comments

@nomeata
Copy link
Contributor

nomeata commented Jan 31, 2017

I regularly find myself in the need of splitting a map into two maps. For that we currently have these two functions:

split :: Ord k => k -> Map k a -> (Map k a, Map k a)
splitLookup :: Ord k => k -> Map k a -> (Map k a, Maybe a, Map k a) 

Usually, split is useless to me because information (the element right on the border) gets lost. splitLookup preserves the information, but often I want the element at the border to simply be in one of the two output maps. So I would like to see

splitL :: Ord k => k -> Map k a -> (Map k a, Map k a)
splitR :: Ord k => k -> Map k a -> (Map k a, Map k a)

with these properties

uncurry union (splitL k m) == m
uncurry union (splitR k m) == m
all (<= k) (keys (fst (splitL k m))
all (> k)  (keys (snd (splitL k m))
all (< k)  (keys (fst (splitR k m))
all (>= k) (keys (snd (splitR k m))

#167 is related.

I will bring this before the libraries list; this issue is mostly for future reference and discoverability.

@nomeata
Copy link
Contributor Author

nomeata commented Jan 31, 2017

I was pointed to splitAntitone, which solves this nicely (via splitL k = splitAntitone (<= k) and splitR k = splitAntitone (< k)) . Closing for now, unless people speak up who really want these convenience functions.

@Icelandjack
Copy link

spanAntitone, not split.

@nomeata
Copy link
Contributor Author

nomeata commented Feb 1, 2017

Of course.

@nomeata
Copy link
Contributor Author

nomeata commented Feb 20, 2017

spanAntitone will do fine, closing this.

@nomeata nomeata closed this as completed Feb 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants