    -- |
    -- Extensions to the standard mutable Vector API.
    module VectorBuilder.MVector where

    import Data.Vector.Generic.Mutable
    import qualified VectorBuilder.Core.Builder as A
    import qualified VectorBuilder.Core.Update as C
    import VectorBuilder.Prelude

    -- |
    -- Construct a mutable vector from a builder.
    --
    -- Supports all kinds of vectors: boxed, unboxed, primitive, storable.
    {-# INLINEABLE build #-}
    build :: (MVector vector element) => A.Builder element -> ST s (vector s element)
    build :: forall (vector :: * -> * -> *) element s.
    MVector vector element =>
    Builder element -> ST s (vector s element)
    build (A.Builder Int
    size (C.Update forall s (vector :: * -> * -> *).
    MVector vector element =>
    vector s element -> Int -> ST s ()
    update)) =
      do
        vector <- Int -> ST s (vector (PrimState (ST s)) element)
    forall (m :: * -> *) (v :: * -> * -> *) a.
    (PrimMonad m, MVector v a) =>
    Int -> m (v (PrimState m) a)
    unsafeNew Int
    size
        update vector 0
        return vector