Skip to content

Add variants of split #387

Closed
Closed
@nomeata

Description

@nomeata

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions