module Data.Sequence.Extended
    ( module Data.Sequence
    , cons
    , safeIndex
    ) where

import Data.Sequence

cons :: a -> Seq a -> Seq a
cons :: forall a. a -> Seq a -> Seq a
cons a
x Seq a
xs = a -> Seq a
forall a. a -> Seq a
singleton a
x Seq a -> Seq a -> Seq a
forall a. Semigroup a => a -> a -> a
<> Seq a
xs

safeIndex :: Seq a -> Int -> Maybe a
safeIndex :: forall a. Seq a -> Int -> Maybe a
safeIndex Seq a
s Int
n
    | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0                       = Maybe a
forall a. Maybe a
Nothing
    | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Seq a -> Int
forall a. Seq a -> Int
Data.Sequence.length Seq a
s = Maybe a
forall a. Maybe a
Nothing
    | Bool
otherwise                   = a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Seq a -> Int -> a
forall a. Seq a -> Int -> a
index Seq a
s Int
n