containers icon indicating copy to clipboard operation
containers copied to clipboard

Analogues of `{dropWhile,takeWhile}Antitone` for `IntMap` and `IntSet`

Open sjakobi opened this issue 2 years ago • 3 comments

Map and Set have these operations, and there is no obvious reason why IntMap and IntSet shouldn't have them too.

If translated directly, the type signature would look like this:

dropWhileAntitone :: (Key -> Bool) -> IntMap a -> IntMap a
takeWhileAntitone :: (Key -> Bool) -> IntMap a -> IntMap a

sjakobi avatar Jun 07 '22 12:06 sjakobi

An alternative design could look like this:

data Compare = LessThan | LessThanEqual | GreaterThanEqual | GreaterThan -- | Equal ?

filterCompare :: Compare -> Key -> IntMap a -> IntMap a

The main advantage is that such a function would do the job of both dropWhileAntitone and takeWhileAntitone.

For simplicity and consistency with Map and Set I think direct translations might be best though.

sjakobi avatar Jun 07 '22 12:06 sjakobi

Consistency is good.

treeowl avatar Jun 07 '22 14:06 treeowl

For consistency, spanAntitone should be added too.

sjakobi avatar Jun 07 '22 14:06 sjakobi

I took a shot at implementing this, should I send a PR?

meooow25 avatar Nov 19 '22 00:11 meooow25

@meooow25 That would surely be appreciated!

treeowl avatar Nov 19 '22 00:11 treeowl