<div dir="ltr">Hi John,<div><br></div><div>this is a nice way of expressing it! I was hoping there would be some more fundamental function that I would have missed though. By fundamental I mean that I was hoping there was some function of a "core" typeclass like Alternative that I had missed that was a general case of my function. Thanks anyway, I learned about lens' partsOf :)</div><div><br></div><div>Paul</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Apr 8, 2017 at 11:20 PM John Wiegley <<a href="mailto:johnw@newartisans.com">johnw@newartisans.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">>>>>> "PB" == Paul Brauner <<a href="mailto:polux2001@gmail.com" class="gmail_msg" target="_blank">polux2001@gmail.com</a>> writes:<br class="gmail_msg">
<br class="gmail_msg">
PB> Oops, there's a free variable in there, let me fix it:<br class="gmail_msg">
PB> first f [] = Nothing<br class="gmail_msg">
PB> first f (x:xs) = fmap (:xs) (f x) <|> fmap (x:) (first f xs)<br class="gmail_msg">
<br class="gmail_msg">
If you break up the test from the modification (instead of fusing the<br class="gmail_msg">
operation into 'f'), this sort of thing becomes quite easy to express<br class="gmail_msg">
using lens:<br class="gmail_msg">
<br class="gmail_msg">
  [1..10] & partsOf (traverse.filtered (>2))._head +~ 3<br class="gmail_msg">
<br class="gmail_msg">
If the list has no elements >2, the operation is a no-op.<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F<br class="gmail_msg">
<a href="http://newartisans.com" rel="noreferrer" class="gmail_msg" target="_blank">http://newartisans.com</a>                          60E1 46C4 BD1A 7AC1 4BA2<br class="gmail_msg">
</blockquote></div>