{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE Trustworthy #-}
-- |
-- Module      : Data.Vector.NonEmpty.Internal
-- Copyright   : (c) 2019-2020 Emily Pillmore
-- License     : BSD-style
--
-- Maintainer  : Emily Pillmore <emilypi@cohomolo.gy>
-- Stability   : experimental
-- Portability : non-portable
--
-- Internal module exposing the constructors for
-- 'NonEmptyVector' and 'NonEmptyMVector'.
--
-- /Warning/: Since the constructors are exposed here, by using this
-- module, you take on the risks that you break the non-emptiness
-- invariants of the main modules. Use at your own risk.
--
-- @since 0.2.1.0
--
module Data.Vector.NonEmpty.Internal
( -- * Immutable boxed vectors
  NonEmptyVector(..)
  -- * Mutable boxed vectors
, NonEmptyMVector(..)
  -- ** Mutable vector aliases
, NonEmptyIOVector
, NonEmptySTVector
) where


import Control.DeepSeq (NFData)
import Control.Monad.ST
import Control.Monad.Zip (MonadZip)

import Data.Data (Data)
import qualified Data.Foldable as Foldable
import Data.Functor.Classes (Eq1, Ord1, Show1, Read1(..))
import qualified Data.Vector as V
#if __GLASGOW_HASKELL__ < 804
import Data.Semigroup (Semigroup(..))
#endif
import Data.Typeable (Typeable)
import Data.Vector.Mutable (MVector)

import qualified Text.Read as Read


-- ---------------------------------------------------------------------- --
-- Non-empty immutable vectors

-- | 'NonEmptyVector' is a thin wrapper around 'Vector' that
-- witnesses an API requiring non-empty construction,
-- initialization, and generation of non-empty vectors by design.
--
-- A newtype wrapper was chosen so that no new pointer indirection
-- is introduced when working with 'Vector's, and all performance
-- characteristics inherited from the 'Vector' API still apply.
--
-- @since 0.2.1.0
--
newtype NonEmptyVector a = NonEmptyVector
    { NonEmptyVector a -> Vector a
_neVec :: V.Vector a
    } deriving
      ( NonEmptyVector a -> NonEmptyVector a -> Bool
(NonEmptyVector a -> NonEmptyVector a -> Bool)
-> (NonEmptyVector a -> NonEmptyVector a -> Bool)
-> Eq (NonEmptyVector a)
forall a. Eq a => NonEmptyVector a -> NonEmptyVector a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NonEmptyVector a -> NonEmptyVector a -> Bool
$c/= :: forall a. Eq a => NonEmptyVector a -> NonEmptyVector a -> Bool
== :: NonEmptyVector a -> NonEmptyVector a -> Bool
$c== :: forall a. Eq a => NonEmptyVector a -> NonEmptyVector a -> Bool
Eq, Eq (NonEmptyVector a)
Eq (NonEmptyVector a)
-> (NonEmptyVector a -> NonEmptyVector a -> Ordering)
-> (NonEmptyVector a -> NonEmptyVector a -> Bool)
-> (NonEmptyVector a -> NonEmptyVector a -> Bool)
-> (NonEmptyVector a -> NonEmptyVector a -> Bool)
-> (NonEmptyVector a -> NonEmptyVector a -> Bool)
-> (NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a)
-> (NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a)
-> Ord (NonEmptyVector a)
NonEmptyVector a -> NonEmptyVector a -> Bool
NonEmptyVector a -> NonEmptyVector a -> Ordering
NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall a. Ord a => Eq (NonEmptyVector a)
forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Bool
forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Ordering
forall a.
Ord a =>
NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
min :: NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
$cmin :: forall a.
Ord a =>
NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
max :: NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
$cmax :: forall a.
Ord a =>
NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
>= :: NonEmptyVector a -> NonEmptyVector a -> Bool
$c>= :: forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Bool
> :: NonEmptyVector a -> NonEmptyVector a -> Bool
$c> :: forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Bool
<= :: NonEmptyVector a -> NonEmptyVector a -> Bool
$c<= :: forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Bool
< :: NonEmptyVector a -> NonEmptyVector a -> Bool
$c< :: forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Bool
compare :: NonEmptyVector a -> NonEmptyVector a -> Ordering
$ccompare :: forall a. Ord a => NonEmptyVector a -> NonEmptyVector a -> Ordering
$cp1Ord :: forall a. Ord a => Eq (NonEmptyVector a)
Ord
      , (a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
(forall a b.
 (a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool)
-> Eq1 NonEmptyVector
forall a b.
(a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
forall (f :: * -> *).
(forall a b. (a -> b -> Bool) -> f a -> f b -> Bool) -> Eq1 f
liftEq :: (a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
$cliftEq :: forall a b.
(a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
Eq1, Eq1 NonEmptyVector
Eq1 NonEmptyVector
-> (forall a b.
    (a -> b -> Ordering)
    -> NonEmptyVector a -> NonEmptyVector b -> Ordering)
-> Ord1 NonEmptyVector
(a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
forall a b.
(a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
forall (f :: * -> *).
Eq1 f
-> (forall a b. (a -> b -> Ordering) -> f a -> f b -> Ordering)
-> Ord1 f
liftCompare :: (a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
$cliftCompare :: forall a b.
(a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
$cp1Ord1 :: Eq1 NonEmptyVector
Ord1, (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS
(forall a.
 (Int -> a -> ShowS)
 -> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS)
-> (forall a.
    (Int -> a -> ShowS)
    -> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS)
-> Show1 NonEmptyVector
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS
forall (f :: * -> *).
(forall a.
 (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> f a -> ShowS)
-> (forall a.
    (Int -> a -> ShowS) -> ([a] -> ShowS) -> [f a] -> ShowS)
-> Show1 f
liftShowList :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS
$cliftShowList :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS
liftShowsPrec :: (Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
$cliftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
Show1
      , Typeable (NonEmptyVector a)
DataType
Constr
Typeable (NonEmptyVector a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> NonEmptyVector a
    -> c (NonEmptyVector a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (NonEmptyVector a))
-> (NonEmptyVector a -> Constr)
-> (NonEmptyVector a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (NonEmptyVector a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (NonEmptyVector a)))
-> ((forall b. Data b => b -> b)
    -> NonEmptyVector a -> NonEmptyVector a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> NonEmptyVector a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> NonEmptyVector a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> NonEmptyVector a -> m (NonEmptyVector a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> NonEmptyVector a -> m (NonEmptyVector a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> NonEmptyVector a -> m (NonEmptyVector a))
-> Data (NonEmptyVector a)
NonEmptyVector a -> DataType
NonEmptyVector a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (NonEmptyVector a))
(forall b. Data b => b -> b)
-> NonEmptyVector a -> NonEmptyVector a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NonEmptyVector a -> c (NonEmptyVector a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NonEmptyVector a)
forall a. Data a => Typeable (NonEmptyVector a)
forall a. Data a => NonEmptyVector a -> DataType
forall a. Data a => NonEmptyVector a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b)
-> NonEmptyVector a -> NonEmptyVector a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> NonEmptyVector a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> NonEmptyVector a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NonEmptyVector a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NonEmptyVector a -> c (NonEmptyVector a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NonEmptyVector a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NonEmptyVector a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> NonEmptyVector a -> u
forall u. (forall d. Data d => d -> u) -> NonEmptyVector a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NonEmptyVector a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NonEmptyVector a -> c (NonEmptyVector a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (NonEmptyVector a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NonEmptyVector a))
$cNonEmptyVector :: Constr
$tNonEmptyVector :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
gmapMp :: (forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
gmapM :: (forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d)
-> NonEmptyVector a -> m (NonEmptyVector a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> NonEmptyVector a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> NonEmptyVector a -> u
gmapQ :: (forall d. Data d => d -> u) -> NonEmptyVector a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> NonEmptyVector a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> NonEmptyVector a -> r
gmapT :: (forall b. Data b => b -> b)
-> NonEmptyVector a -> NonEmptyVector a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b)
-> NonEmptyVector a -> NonEmptyVector a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NonEmptyVector a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (NonEmptyVector a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (NonEmptyVector a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (NonEmptyVector a))
dataTypeOf :: NonEmptyVector a -> DataType
$cdataTypeOf :: forall a. Data a => NonEmptyVector a -> DataType
toConstr :: NonEmptyVector a -> Constr
$ctoConstr :: forall a. Data a => NonEmptyVector a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NonEmptyVector a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (NonEmptyVector a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NonEmptyVector a -> c (NonEmptyVector a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> NonEmptyVector a -> c (NonEmptyVector a)
$cp1Data :: forall a. Data a => Typeable (NonEmptyVector a)
Data, Typeable, NonEmptyVector a -> ()
(NonEmptyVector a -> ()) -> NFData (NonEmptyVector a)
forall a. NFData a => NonEmptyVector a -> ()
forall a. (a -> ()) -> NFData a
rnf :: NonEmptyVector a -> ()
$crnf :: forall a. NFData a => NonEmptyVector a -> ()
NFData
      , a -> NonEmptyVector b -> NonEmptyVector a
(a -> b) -> NonEmptyVector a -> NonEmptyVector b
(forall a b. (a -> b) -> NonEmptyVector a -> NonEmptyVector b)
-> (forall a b. a -> NonEmptyVector b -> NonEmptyVector a)
-> Functor NonEmptyVector
forall a b. a -> NonEmptyVector b -> NonEmptyVector a
forall a b. (a -> b) -> NonEmptyVector a -> NonEmptyVector b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> NonEmptyVector b -> NonEmptyVector a
$c<$ :: forall a b. a -> NonEmptyVector b -> NonEmptyVector a
fmap :: (a -> b) -> NonEmptyVector a -> NonEmptyVector b
$cfmap :: forall a b. (a -> b) -> NonEmptyVector a -> NonEmptyVector b
Functor, Functor NonEmptyVector
a -> NonEmptyVector a
Functor NonEmptyVector
-> (forall a. a -> NonEmptyVector a)
-> (forall a b.
    NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b)
-> (forall a b c.
    (a -> b -> c)
    -> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c)
-> (forall a b.
    NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b)
-> (forall a b.
    NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a)
-> Applicative NonEmptyVector
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a
NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
forall a. a -> NonEmptyVector a
forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a
forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
forall a b.
NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b
forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a
$c<* :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a
*> :: NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
$c*> :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
liftA2 :: (a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
$cliftA2 :: forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
<*> :: NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b
$c<*> :: forall a b.
NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b
pure :: a -> NonEmptyVector a
$cpure :: forall a. a -> NonEmptyVector a
$cp1Applicative :: Functor NonEmptyVector
Applicative, Applicative NonEmptyVector
a -> NonEmptyVector a
Applicative NonEmptyVector
-> (forall a b.
    NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b)
-> (forall a b.
    NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b)
-> (forall a. a -> NonEmptyVector a)
-> Monad NonEmptyVector
NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
forall a. a -> NonEmptyVector a
forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
forall a b.
NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> NonEmptyVector a
$creturn :: forall a. a -> NonEmptyVector a
>> :: NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
$c>> :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
>>= :: NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b
$c>>= :: forall a b.
NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b
$cp1Monad :: Applicative NonEmptyVector
Monad
      , Monad NonEmptyVector
Monad NonEmptyVector
-> (forall a b.
    NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b))
-> (forall a b c.
    (a -> b -> c)
    -> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c)
-> (forall a b.
    NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b))
-> MonadZip NonEmptyVector
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b)
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
forall a b.
NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b)
forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
forall (m :: * -> *).
Monad m
-> (forall a b. m a -> m b -> m (a, b))
-> (forall a b c. (a -> b -> c) -> m a -> m b -> m c)
-> (forall a b. m (a, b) -> (m a, m b))
-> MonadZip m
munzip :: NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b)
$cmunzip :: forall a b.
NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b)
mzipWith :: (a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
$cmzipWith :: forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
mzip :: NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
$cmzip :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
$cp1MonadZip :: Monad NonEmptyVector
MonadZip
      , b -> NonEmptyVector a -> NonEmptyVector a
NonEmpty (NonEmptyVector a) -> NonEmptyVector a
NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
(NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a)
-> (NonEmpty (NonEmptyVector a) -> NonEmptyVector a)
-> (forall b.
    Integral b =>
    b -> NonEmptyVector a -> NonEmptyVector a)
-> Semigroup (NonEmptyVector a)
forall b. Integral b => b -> NonEmptyVector a -> NonEmptyVector a
forall a. NonEmpty (NonEmptyVector a) -> NonEmptyVector a
forall a. NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> NonEmptyVector a -> NonEmptyVector a
stimes :: b -> NonEmptyVector a -> NonEmptyVector a
$cstimes :: forall a b. Integral b => b -> NonEmptyVector a -> NonEmptyVector a
sconcat :: NonEmpty (NonEmptyVector a) -> NonEmptyVector a
$csconcat :: forall a. NonEmpty (NonEmptyVector a) -> NonEmptyVector a
<> :: NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
$c<> :: forall a. NonEmptyVector a -> NonEmptyVector a -> NonEmptyVector a
Semigroup
      )

instance Show a => Show (NonEmptyVector a) where
    show :: NonEmptyVector a -> String
show (NonEmptyVector Vector a
v) = Vector a -> String
forall a. Show a => a -> String
show Vector a
v

instance Read a => Read (NonEmptyVector a) where
    readPrec :: ReadPrec (NonEmptyVector a)
readPrec = ReadPrec [a]
forall a. Read a => ReadPrec a
Read.readPrec ReadPrec [a]
-> ([a] -> ReadPrec (NonEmptyVector a))
-> ReadPrec (NonEmptyVector a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      [] -> ReadPrec (NonEmptyVector a)
forall a. ReadPrec a
Read.pfail
      [a]
as -> NonEmptyVector a -> ReadPrec (NonEmptyVector a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector a -> NonEmptyVector a
forall a. Vector a -> NonEmptyVector a
NonEmptyVector (Vector a -> NonEmptyVector a) -> Vector a -> NonEmptyVector a
forall a b. (a -> b) -> a -> b
$ [a] -> Vector a
forall a. [a] -> Vector a
V.fromList [a]
as)

instance Read1 NonEmptyVector where
#if __GLASGOW_HASKELL__ > 802
    liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (NonEmptyVector a)
liftReadPrec ReadPrec a
_ ReadPrec [a]
rl = ReadPrec [a]
rl ReadPrec [a]
-> ([a] -> ReadPrec (NonEmptyVector a))
-> ReadPrec (NonEmptyVector a)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
      [] -> ReadPrec (NonEmptyVector a)
forall a. ReadPrec a
Read.pfail
      [a]
as -> NonEmptyVector a -> ReadPrec (NonEmptyVector a)
forall (m :: * -> *) a. Monad m => a -> m a
return (Vector a -> NonEmptyVector a
forall a. Vector a -> NonEmptyVector a
NonEmptyVector (Vector a -> NonEmptyVector a) -> Vector a -> NonEmptyVector a
forall a b. (a -> b) -> a -> b
$ [a] -> Vector a
forall a. [a] -> Vector a
V.fromList [a]
as)
#else
    liftReadsPrec _ r _ s = r s >>= \case
      ([], _) -> []
      (as, s') -> return (NonEmptyVector $ V.fromList as, s')
#endif

instance Foldable NonEmptyVector where
    foldMap :: (a -> m) -> NonEmptyVector a -> m
foldMap a -> m
f = (a -> m) -> Vector a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
Foldable.foldMap a -> m
f (Vector a -> m)
-> (NonEmptyVector a -> Vector a) -> NonEmptyVector a -> m
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyVector a -> Vector a
forall a. NonEmptyVector a -> Vector a
_neVec

instance Traversable NonEmptyVector where
    traverse :: (a -> f b) -> NonEmptyVector a -> f (NonEmptyVector b)
traverse a -> f b
f = (Vector b -> NonEmptyVector b)
-> f (Vector b) -> f (NonEmptyVector b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Vector b -> NonEmptyVector b
forall a. Vector a -> NonEmptyVector a
NonEmptyVector (f (Vector b) -> f (NonEmptyVector b))
-> (NonEmptyVector a -> f (Vector b))
-> NonEmptyVector a
-> f (NonEmptyVector b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> f b) -> Vector a -> f (Vector b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f (Vector a -> f (Vector b))
-> (NonEmptyVector a -> Vector a)
-> NonEmptyVector a
-> f (Vector b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmptyVector a -> Vector a
forall a. NonEmptyVector a -> Vector a
_neVec

-- ---------------------------------------------------------------------- --
-- Non-empty mutable vectors

-- | 'NonEmptyMVector' is a thin wrapper around 'MVector' that
-- witnesses an API requiring non-empty construction,
-- initialization, and generation of non-empty vectors by design.
--
-- A newtype wrapper was chosen so that no new pointer indirection
-- is introduced when working with 'MVector's, and all performance
-- characteristics inherited from the 'MVector' API still apply.
--
-- @since 0.2.1.0
--
newtype NonEmptyMVector s a = NonEmptyMVector
    { NonEmptyMVector s a -> MVector s a
_nemVec :: MVector s a }
    deriving (Typeable)

-- | 'NonEmptyMVector' parametrized by 'PrimState'
--
-- @since 0.2.1.0
--
type NonEmptyIOVector = NonEmptyMVector RealWorld

-- | 'NonEmptyMVector' parametrized by 'ST'
--
-- @since 0.2.1.0
--
type NonEmptySTVector s = NonEmptyMVector s