PRELUDE: add pivot

This commit is contained in:
hasufell 2014-11-29 05:09:58 +01:00
parent b5a56ea7b0
commit 740c05fc1a
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020
1 changed files with 6 additions and 0 deletions

View File

@ -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