From a9ee47b61558efe09aee23f5671aabd0c3747e8a Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Tue, 17 Mar 2015 11:05:29 +0800 Subject: p -> h --- h2.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 h2.hs (limited to 'h2.hs') diff --git a/h2.hs b/h2.hs new file mode 100644 index 0000000..60693ef --- /dev/null +++ b/h2.hs @@ -0,0 +1,11 @@ +import Data.Foldable as F + +myButLast :: Foldable f => f a -> a + +myButLast = fst . F.foldl (\(a,b) x -> (b,x)) (err1, err2) + where + err1 = error "Empty list" + err2 = error "Not enough elements" + +mySafeButLast :: Foldable f => f a -> Maybe a +mySafeButLast = fst . F.foldl (\(a,b) x -> (b,Just x)) (Nothing, Nothing) -- cgit v1.2.3-70-g09d2