{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
-- |
-- Module      : Data.Vector.NonEmpty.Internal
-- Copyright   : (c) 2019-2023 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
#if MIN_VERSION_base(4,18,0)
import Data.Foldable1 (Foldable1)
import qualified Data.Foldable1 as Foldable1
#endif
import Data.Functor.Classes (Eq1, Ord1, Show1, Read1(..))
import qualified Data.Vector as V
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
    { forall a. NonEmptyVector a -> Vector a
_neVec :: V.Vector a
    } deriving
      ( NonEmptyVector a -> NonEmptyVector a -> Bool
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, 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
Ord
      , 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 :: forall a b.
(a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
$cliftEq :: forall a b.
(a -> b -> Bool) -> NonEmptyVector a -> NonEmptyVector b -> Bool
Eq1, Eq1 NonEmptyVector
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 :: forall a b.
(a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
$cliftCompare :: forall a b.
(a -> b -> Ordering)
-> NonEmptyVector a -> NonEmptyVector b -> Ordering
Ord1, 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 :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS
$cliftShowList :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> [NonEmptyVector a] -> ShowS
liftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
$cliftShowsPrec :: forall a.
(Int -> a -> ShowS)
-> ([a] -> ShowS) -> Int -> NonEmptyVector a -> ShowS
Show1
      , NonEmptyVector a -> DataType
NonEmptyVector a -> Constr
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 (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))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(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 (m :: * -> *).
MonadPlus m =>
(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 (m :: * -> *).
Monad m =>
(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 :: forall u.
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 u. (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 :: forall r r'.
(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 :: forall r r'.
(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 (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(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 (t :: * -> *) (c :: * -> *).
Typeable t =>
(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 (c :: * -> *).
(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 (c :: * -> *).
(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)
Data, Typeable, NonEmptyVector a -> ()
forall a. NFData a => NonEmptyVector a -> ()
forall a. (a -> ()) -> NFData a
rnf :: NonEmptyVector a -> ()
$crnf :: forall a. NFData a => NonEmptyVector a -> ()
NFData
      , 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
<$ :: forall a b. a -> NonEmptyVector b -> NonEmptyVector a
$c<$ :: forall a b. a -> NonEmptyVector b -> NonEmptyVector a
fmap :: forall a b. (a -> b) -> NonEmptyVector a -> NonEmptyVector b
$cfmap :: forall a b. (a -> b) -> NonEmptyVector a -> NonEmptyVector b
Functor, Functor NonEmptyVector
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
<* :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a
$c<* :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector a
*> :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
$c*> :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
liftA2 :: forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
$cliftA2 :: forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
<*> :: forall a b.
NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b
$c<*> :: forall a b.
NonEmptyVector (a -> b) -> NonEmptyVector a -> NonEmptyVector b
pure :: forall a. a -> NonEmptyVector a
$cpure :: forall a. a -> NonEmptyVector a
Applicative, Applicative NonEmptyVector
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 :: forall a. a -> NonEmptyVector a
$creturn :: forall a. a -> NonEmptyVector a
>> :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
$c>> :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector b
>>= :: forall a b.
NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b
$c>>= :: forall a b.
NonEmptyVector a -> (a -> NonEmptyVector b) -> NonEmptyVector b
Monad
      , Monad NonEmptyVector
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 :: forall a b.
NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b)
$cmunzip :: forall a b.
NonEmptyVector (a, b) -> (NonEmptyVector a, NonEmptyVector b)
mzipWith :: forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
$cmzipWith :: forall a b c.
(a -> b -> c)
-> NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector c
mzip :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
$cmzip :: forall a b.
NonEmptyVector a -> NonEmptyVector b -> NonEmptyVector (a, b)
MonadZip
      , NonEmpty (NonEmptyVector a) -> NonEmptyVector a
NonEmptyVector a -> NonEmptyVector a -> 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 :: forall b. Integral b => 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) = forall a. Show a => a -> String
show Vector a
v

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

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

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

#if MIN_VERSION_base(4,18,0)
instance Foldable1 NonEmptyVector where
    foldMap1 f (NonEmptyVector v) =
        let
          h = V.unsafeHead v -- gauranteed head (nonemptiness)
          t = V.unsafeTail v -- gauranteed possibly empty tail
        in go (f h) t -- therefore this is a sound call
      where
        go x xs
          -- when xs is empty, vector is exhausted, return x
          | V.null xs = x
          | otherwise =
          -- if xs is not empty, then there are at least 2 elements in the list. Hence, h and t are sound calls to make.
            let
              h = V.unsafeHead xs
              t = V.unsafeTail xs
            in x <> go (f h) t
#endif

instance Traversable NonEmptyVector where
    traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> NonEmptyVector a -> f (NonEmptyVector b)
traverse a -> f b
f = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall a. Vector a -> NonEmptyVector a
NonEmptyVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
traverse a -> f b
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
    { forall s a. 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