blob: 17516938c11b984b4d093faaf6bbd516517a3c9b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
{-# OPTIONS_GHC -Wincomplete-patterns -fforce-recomp #-}
{-# LANGUAGE ViewPatterns #-}
module Lib where
safeLast :: [a] -> Maybe a
safeLast xs
| [] <- reverse xs = Nothing
| (x:_) <- reverse xs = Just x
safeLast2 :: [a] -> Maybe a
safeLast2 (reverse -> []) = Nothing
safeLast2 (reverse -> (x:_)) = Just x
|