haskell / haskell/containers

Add `spanAntitoneM`

Open
#798 4 comments 0 reactions 0 assignees View on GitHub
feature-request IntMap Map
Dominant language
Haskell
Stars
355
Forks
194
Avg merge
3d 4h
Merged PRs (30d)
4

Description

`spanAntitone :: (k -> Bool) -> Map k a -> (Map k a, Map k a)` is a handy way to "bisect" arbitrary data in the `git bisect` sense. Just stick your data in a `Map`, then use `spanAntitone` to find the crossover point.

Sometimes the antitone predicate cannot be defined purely though (maybe it involves interactivity, or consulting a database, or whatever), and in such cases I feel like it'd be handy to have this slight variation:

```haskell
spanAntitoneM :: Monad m => (k -> m Bool) -> Map k a -> m (Map k a, Map k a)
```

The rule for the predicate can still be specified as `j < k implies (>=) <$> p j <*> p k == f True`, for some `f :: forall x. x -> m x` (roughly, `(>=) <$> p j <*> p k` always "resolves" to `True`).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.