module Incipit.List where
import qualified Data.List as List
import Data.Maybe (Maybe (..))
head :: [a] -> Maybe a
head :: forall a. [a] -> Maybe a
head = \case
[] -> Maybe a
forall a. Maybe a
Nothing
a
a : [a]
_ -> a -> Maybe a
forall a. a -> Maybe a
Just a
a
{-# inline head #-}
last :: [a] -> Maybe a
last :: forall a. [a] -> Maybe a
last = \case
[] -> Maybe a
forall a. Maybe a
Nothing
[a]
as -> a -> Maybe a
forall a. a -> Maybe a
Just ([a] -> a
forall a. HasCallStack => [a] -> a
List.last [a]
as)
{-# inline last #-}
init :: [a] -> Maybe [a]
init :: forall a. [a] -> Maybe [a]
init = \case
[] -> Maybe [a]
forall a. Maybe a
Nothing
[a]
as -> [a] -> Maybe [a]
forall a. a -> Maybe a
Just ([a] -> [a]
forall a. HasCallStack => [a] -> [a]
List.init [a]
as)
{-# inline init #-}
tail :: [a] -> Maybe [a]
tail :: forall a. [a] -> Maybe [a]
tail = \case
[] -> Maybe [a]
forall a. Maybe a
Nothing
[a]
as -> [a] -> Maybe [a]
forall a. a -> Maybe a
Just ([a] -> [a]
forall a. HasCallStack => [a] -> [a]
List.tail [a]
as)
{-# inline tail #-}