<html><head></head><body>This sounds like 'unconsAt', if 'uncons' isn't already too obtuse.<br><br><div class="gmail_quote">On December 28, 2019 8:06:21 PM UTC, David Feuer <david.feuer@gmail.com> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div dir="auto"><div>Written natively, it would surely borrow the machinery of deleteAt, which does quite a bit less reshuffling. It's actually a finger-twisted version of a classical 2-3 tree deletion.<br><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Dec 28, 2019, 2:59 PM Zemyla <<a href="mailto:zemyla@gmail.com">zemyla@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">deleteLookup :: Int -> Seq a -> Maybe (a, Seq a)<br>
deleteLookup n q = case Seq.splitAt n q of<br>
(ql, qr) -> case Seq.viewl qr of<br>
Seq.EmptyL -> Nothing<br>
(Seq.:<) a qr' -> Just (a, ql <> qr')</p>
<p dir="ltr">If it were written natively, it'd probably use some of the machinery from splitAt.</p>
<br><div class="gmail_quote"><div dir="ltr">On 13:25, Sat, Dec 28, 2019 David Feuer <<a href="mailto:david.feuer@gmail.com" target="_blank" rel="noreferrer">david.feuer@gmail.com</a> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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" rel="noreferrer noreferrer" target="_blank">Libraries@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>
</blockquote></div></div></div>
</blockquote></div><br>-- <br>Sent from my Android device with K-9 Mail. Please excuse my brevity.</body></html>