<div dir="auto"><div>That approach works great for maps and sets, but not so well for sequences. If a sequence has ten elements, then you can't really insert a twentieth one.<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Dec 28, 2019, 7:25 PM Andreas Abel <<a href="mailto:andreas.abel@ifi.lmu.de">andreas.abel@ifi.lmu.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'd advocate a Swiss army knife like<br>
<br>
   atM<br>
     :: Applicative m<br>
     => Int<br>
     -> (Maybe a -> m (Maybe a))<br>
     -> Seq a -> m (Seq a)<br>
<br>
Then you can get your deleteLookup function by a suitable instance of <br>
the effect m.<br>
<br>
Nothing stands for "index does not point to any element", "Just a" means <br>
the index points to value a.<br>
<br>
On 2019-12-28 20:24, David Feuer wrote:<br>
> Data.Sequence offers<br>
> <br>
>    deleteAt :: Int -> Seq a -> Seq a<br>
> <br>
> which deletes the element at the given index. Today, I ran into a<br>
> situation where I wanted to know what was deleted.<br>
> <br>
>    deleteLookup :: Int -> Seq a -> Maybe (a, Seq a)<br>
> <br>
> The closest thing I can find in `containers` is in Data.Map:<br>
> <br>
>    updateLookupWithKey :: Ord k => (k -> a -> Maybe a) -> k -> Map k a<br>
> -> (Maybe a,Map k a)<br>
> <br>
> Unfortunately, that function is ugly and strange. A better one, whose<br>
> name I can't guess at the moment:<br>
> <br>
>    flabbergast :: (a -> (b, Maybe a)) -> Int -> Seq a -> Maybe (b, Seq a)<br>
> <br>
> where a Nothing result means the index was out of bounds. There's also<br>
> a potential<br>
> <br>
>    flabbergastF :: Functor f => (a -> f (Maybe a)) -> Int -> Seq a -><br>
> Maybe (f (Seq a))<br>
> <br>
> I'm not sure if flabbergast can be made as fast as deleteLookup, so<br>
> it's possible we may want both. Any opinions?<br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
> <br>
_______________________________________________<br>
Libraries mailing list<br>
<a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div></div></div>