<div dir="ltr">On Sat, Aug 6, 2016 at 11:15 PM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Set:<br>
<br>
filterIncreasing :: Ord a => (a -> Bool) -> Set a -> Set a<br>
filterDecreasing :: Ord a => (a -> Bool) -> Set a -> Set a<br>
partitionIncreasing :: Ord a => (a -> Bool) -> Set a -> (Set a, Set a)<br>
<br>
Map:<br>
<br>
filterKeysIncreasing :: Ord k => (k -> Bool) -> Map k a -> Map k a<br>
filterKeysDecreasing :: Ord k => (k -> Bool) -> Map k a -> Map k a<br>
partitionKeysIncreasing :: Ord k => (k -> Bool) -> Map k a -> (Map k a, Map k a)<br></blockquote><div><br></div><div>Are there good examples of increasing / decreasing predicates that don't embed a split element?  Because split already gives the results you want.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">alterMany :: Ord k => (a -> Maybe b -> Maybe b) -> Map k a -> Map k b -> Map k b<br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">unionWithMapping :: Ord k => (a -> c) -> (b -> c) -> (a -> b -> c) -><br>
Map k a -> Map k b -> Map k c<br>
<br>
unionWithKeyMapping :: Ord k => (k -> a -> c) -> (k -> b -> c) -> (k<br>
-> a -> b -> c)<br>
-> Map k a -> Map k b -> Map k c<br></blockquote><div><br></div><div>Note that these three are each one-liners given mergeWithKey:</div><div><br></div><div>alterMany c = mergeWithKey (\_ a b -> c a (Just b)) (mapMaybe (\a -> c a Nothing)) (const empty)</div><div>unionWithMapping f g c = mergeWithKey (\_ a b -> Just (c a b)) (fmap f) (fmap g)</div><div>unionWithKeyMapping f g c = mergeWithKey (\k a b -> Just (c k a b)) (mapWithKey f) (mapWithKey g)</div><div><br></div><div>There's a pretty large combinatorial space of these functions – I'm not sure Data.Map and Data.Set should fill that entire space with individually-named functions.</div><div><br></div><div>The applicative versions suggest there might want to be an applicative-friendly version of mergeWithKey, but again it's not obvious we need the 32767 different combinations of individual functions.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
______________________________<wbr>_________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/libraries</a><br>
</blockquote></div><br></div></div>