
8 Apr
2017
8 Apr
'17
5:20 p.m.
"PB" == Paul Brauner
writes:
PB> Oops, there's a free variable in there, let me fix it: PB> first f [] = Nothing PB> first f (x:xs) = fmap (:xs) (f x) <|> fmap (x:) (first f xs) If you break up the test from the modification (instead of fusing the operation into 'f'), this sort of thing becomes quite easy to express using lens: [1..10] & partsOf (traverse.filtered (>2))._head +~ 3 If the list has no elements >2, the operation is a no-op. -- John Wiegley GPG fingerprint = 4710 CF98 AF9B 327B B80F http://newartisans.com 60E1 46C4 BD1A 7AC1 4BA2