Open
Description
import Data.Set.Internal
traverseMonotonic :: Applicative t => (a -> t b) -> Set a -> t (Set b)
traverseMonotonic _ Tip = pure Tip
traverseMonotonic f (Bin sz x l r) = flip (Bin sz) <$> traverseMonotonic f l <*> f x <*> traverseMonotonic f r
import Data.Map.Internal
traverseKeysMonotonic :: Applicative t => (k1 -> t k2) -> Map k1 a -> t (Map k2 a)
traverseKeysMonotonic _ Tip = pure Tip
traverseKeysMonotonic f (Bin sz k x l r) = (\l' k' -> Bin sz k' x l') <$> traverseKeysMonotonic f l <*> f k <*> traverseKeysMonotonic f r
bitraverseMonotonic :: Applicative t => (k1 -> t k2) -> (v1 -> t v2) -> Map k1 v1 -> t (Map k2 v2)
bitraverseMonotonic _ _ Tip = pure Tip
bitraverseMonotonic f g (Bin sz k x l r) = (\l' k' x' -> Bin sz k' x' l') <$> bitraverseMonotonic f g l <*> f k <*> g x <*> bitraverseMonotonic f g r
I think we should add these to Data.Set
and Data.Map
, respectively, as analogues of mapMonotonic
, etc. Note that these are unsafe just like they are, and require the exact same care to avoid breaking invariants.