[Haskell-cafe] When folding is there a way to pick out the last point being processed?

Thomas DuBuisson thomas.dubuisson at gmail.com
Thu Jun 11 22:41:11 EDT 2009


Something like the belo 'foldL_last'?  You could probably do it
cleaner, but I don't think there is a library function that would help
any more than foldl.

foldL_last :: (a -> b -> a) -> a -> [b] -> (Maybe b, a)
foldL_last f x xs = foldl (\(_,a) b -> (Just b, f a b)) (Nothing, x) xs

Tom

On Thu, Jun 11, 2009 at 6:47 PM, Casey Hawthorne<caseyh at istar.ca> wrote:
> When folding is there a way to pick out the last point being
> processed?
>
> The first point can easily be picked out with (x:xs) but last xs
> crawls down the list.
> --
> Regards,
> Casey
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list