summaryrefslogtreecommitdiff
path: root/h2.hs
diff options
context:
space:
mode:
authorJoe Zhao <ztuowen@gmail.com>2015-03-17 11:05:29 +0800
committerJoe Zhao <ztuowen@gmail.com>2015-03-17 11:05:29 +0800
commita9ee47b61558efe09aee23f5671aabd0c3747e8a (patch)
tree52426053545a54514d39300e2117bdda14a9b1ef /h2.hs
parent11a5fd38018498a7b7feb0e392ac36003b0440ac (diff)
downloadh99-a9ee47b61558efe09aee23f5671aabd0c3747e8a.tar.gz
h99-a9ee47b61558efe09aee23f5671aabd0c3747e8a.tar.bz2
h99-a9ee47b61558efe09aee23f5671aabd0c3747e8a.zip
p -> h
Diffstat (limited to 'h2.hs')
-rw-r--r--h2.hs11
1 files changed, 11 insertions, 0 deletions
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)