{-# LANGUAGE Safe #-}
-- | Random access list.
--
-- This module is designed to imported qualifed.
--
module Data.RAList (
    RAList (..),
    -- * Showing
    explicitShow,
    explicitShowsPrec,
    -- * Construction
    empty,
    singleton,
    cons,
    -- * Indexing
    (!),
    (!?),
    uncons,
    length,
    null,
    -- * Conversions
    toList,
    fromList,
    -- * Folding
    ifoldMap,
    -- * Mapping
    adjust,
    map,
    imap,
    itraverse,
    ) where

import Data.RAList.Internal
import Prelude              (Maybe (..))

import qualified Data.RAList.NonEmpty as NE

-- $setup
-- >>> import Prelude (($))

-------------------------------------------------------------------------------
-- Extras
-------------------------------------------------------------------------------

-- |
--
-- >>> uncons $ fromList []
-- Nothing
--
-- >>> uncons $ fromList "abcdef"
-- Just ('a',fromList "bcdef")
--
uncons :: RAList a -> Maybe (a, RAList a)
uncons :: RAList a -> Maybe (a, RAList a)
uncons RAList a
Empty        = Maybe (a, RAList a)
forall a. Maybe a
Nothing
uncons (NonEmpty NERAList a
r) = (a, RAList a) -> Maybe (a, RAList a)
forall a. a -> Maybe a
Just (NERAList a -> (a, RAList a)
forall a. NERAList a -> (a, RAList a)
NE.uncons NERAList a
r)