[Haskell-cafe] Generalizing takeWhile

Felipe Lessa felipe.lessa at gmail.com
Thu Jul 23 01:46:32 EDT 2009


On Thu, Jul 23, 2009 at 07:28:55AM +0200, Matthias Görgens wrote:
] I often want to take one more element than takeWhile does, or only

> takeWhileMore n p x | p x       = Just . F $ takeWhileMore n p
>                     | otherwise = Just . F $ takeN n

] start checking the predicate after taking the first element for sure.

> plusFirst = const . Just . F

] Or both.

> both = plusFirst . takeWhileMore 1

:)

--
Felipe.


More information about the Haskell-Cafe mailing list