From 740c05fc1a6592c0382efdd9599f11cd3e80537a Mon Sep 17 00:00:00 2001 From: hasufell Date: Sat, 29 Nov 2014 05:09:58 +0100 Subject: [PATCH] PRELUDE: add pivot --- MyPrelude.hs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MyPrelude.hs b/MyPrelude.hs index 2b05698..d1bb58b 100644 --- a/MyPrelude.hs +++ b/MyPrelude.hs @@ -85,3 +85,9 @@ shiftM :: Int -> [a] -> [a] shiftM _ [] = [] shiftM 0 xs = xs shiftM n xs = drop n xs ++ take n xs + + +-- |Get the pivot of a list. +pivot :: [a] -> Maybe a +pivot [] = Nothing +pivot xs = Just . (!!) xs . flip div 2 . length $ xs