<div dir="ltr">Yes, that'd be my suggestion.<br></div><br><div class="gmail_quote">čt 26. 2. 2015 v 16:03 odesílatel David Feuer <<a href="mailto:david.feuer@gmail.com">david.feuer@gmail.com</a>> napsal:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">So are you suggesting that we add these to Data.Foldable?</p>
<p dir="ltr">headMay = foldr (\x _ -> Just x) Nothing<br>
lastMay = foldl (\_ x -> Just x) Nothing</p>
<div class="gmail_quote"></div><div class="gmail_quote">On Feb 26, 2015 9:18 AM, "Petr Pudlák" <<a href="mailto:petr.mvd@gmail.com" target="_blank">petr.mvd@gmail.com</a>> wrote:<br type="attribution"></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>today I was a bit surprised that apparently there is no easy way how to safely get the head element of `Seq` in a point-free way. Of course there is `viewl`, but it seems the data type has no folding function (something like 'foldViewL :: b -> (a -> Seq a -> b) -> b`.</div><div><br></div><div>Is there any existing function like `Seq a -> Maybe a` to safely retrieve the head (or last) element?</div><div><br></div><div>If not, I'd suggest to add</div><div><br></div><div> headMaybe :: (Foldable t) => t a -> Maybe a</div><div> headMaybe = getFirst . foldMap (First . Just)</div><div><br></div><div>and similarly lastMaybe to Data.Foldable.</div><div><br></div><div> Thanks,</div><div> Petr</div></div>
<br></blockquote></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org" target="_blank">Haskell-Cafe@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div></blockquote></div>