[Haskell-cafe] Does this function have a name?
polux2001 at gmail.com
Mon Apr 10 08:07:28 UTC 2017
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 :)
On Sat, Apr 8, 2017 at 11:20 PM John Wiegley <johnw at newartisans.com> wrote:
> >>>>> "PB" == Paul Brauner <polux2001 at gmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe