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
[] -> forall a. Maybe a
Nothing
a
a : [a]
_ -> forall a. a -> Maybe a
Just a
a
{-# inline head #-}
last :: [a] -> Maybe a
last :: forall a. [a] -> Maybe a
last = \case
[] -> forall a. Maybe a
Nothing
[a]
as -> forall a. a -> Maybe a
Just (forall a. [a] -> a
List.last [a]
as)
{-# inline last #-}
init :: [a] -> Maybe [a]
init :: forall a. [a] -> Maybe [a]
init = \case
[] -> forall a. Maybe a
Nothing
[a]
as -> forall a. a -> Maybe a
Just (forall a. [a] -> [a]
List.init [a]
as)
{-# inline init #-}
tail :: [a] -> Maybe [a]
tail :: forall a. [a] -> Maybe [a]
tail = \case
[] -> forall a. Maybe a
Nothing
[a]
as -> forall a. a -> Maybe a
Just (forall a. [a] -> [a]
List.tail [a]
as)
{-# inline tail #-}