From 378f7887d48e666062f03fe7d22d89fde5d7dcb2 Mon Sep 17 00:00:00 2001 From: hasufell Date: Sun, 12 Oct 2014 03:00:55 +0200 Subject: [PATCH] PRELUDE: add getLastX --- MyPrelude.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/MyPrelude.hs b/MyPrelude.hs index c81a784..5b1b71f 100644 --- a/MyPrelude.hs +++ b/MyPrelude.hs @@ -34,6 +34,13 @@ sortLex = x -> x) +-- |Get the last x elements of a list. +getLastX :: Int -> [a] -> [a] +getLastX a xs + | length xs < a = [] + | otherwise = snd . splitAt (length xs - a) $ xs + + -- |Get a list with it's head and last element cut. If there are less -- than 2 elements in the list, return an empty list. tailInit :: [a] -> [a]