packages feed

vector-builder 0.3.7 → 0.3.7.1

raw patch · 4 files changed

+35/−7 lines, 4 files

Files

library/VectorBuilder/Core/Builder.hs view
@@ -1,9 +1,10 @@ module VectorBuilder.Core.Builder where -import VectorBuilder.Prelude hiding (empty)+import VectorBuilder.Prelude hiding (empty, concat) import qualified VectorBuilder.Core.Update as A import qualified Data.Vector.Generic as B+import qualified Data.Vector.Generic.Mutable as C   -- |@@ -67,6 +68,17 @@ append =   flip prepend +{-# INLINE concat #-}+concat :: Foldable foldable => foldable (Builder element) -> Builder element+concat builders =+  Builder+    (let+      step size (Builder builderSize _) = size + builderSize+      in foldl' step 0 builders)+    (A.Update (\mVector offset -> foldM_ (\index (Builder size (A.Update st)) ->+      st mVector index $> index + size)+      offset+      builders))  -- * Instances @@ -76,6 +88,8 @@   {-# INLINE (<>) #-}   (<>) =     prepend+  sconcat =+    concat  -- | -- Provides support for /O(1)/ concatenation.@@ -86,5 +100,7 @@   {-# INLINE mappend #-}   mappend =     (<>)-+  {-# INLINE mconcat #-}+  mconcat =+    concat 
tests/Main.hs view
@@ -17,7 +17,7 @@   defaultMain $   testGroup "All tests"   [-    testProperty "" $ \(samples :: [C.Sample Int]) ->+    testProperty "samples" $ \(samples :: [C.Sample Int]) ->       foldMap C.toVector samples ===       B.build (foldMap C.toBuilder samples)     ,@@ -28,5 +28,13 @@     testCase "Alternative.some on empty" $ assertEqual ""       (Left "not enough input")       (D.parseOnly (F.some D.anyChar :: D.Parser (Vector Char)) "")+    ,+    testProperty "mconcat" $ \(samples :: [C.Sample Int]) ->+      foldMap C.toVector samples ===+      B.build (mconcat (map C.toBuilder samples))+    ,+    testProperty "foldable" $ \(elements :: [Int]) ->+      E.fromList elements ===+      B.build (A.foldable elements)   ] 
tests/Main/Sample.hs view
@@ -10,7 +10,8 @@ data Sample a =   Empty |   Singleton a |-  Vector (Vector a)+  Vector (Vector a) |+  List [a]   deriving (Show)  toBuilder :: Sample a -> A.Builder a@@ -19,6 +20,7 @@     Empty -> A.empty     Singleton a -> A.singleton a     Vector a -> A.vector a+    List a -> A.foldable a  toVector :: Sample a -> Vector a toVector =@@ -26,12 +28,14 @@     Empty -> B.empty     Singleton a -> B.singleton a     Vector a -> a+    List a -> B.fromList a  instance C.Arbitrary a => C.Arbitrary (Sample a) where   arbitrary =     do-      constructorIndex <- C.choose (0 :: Int, 2)+      constructorIndex <- C.choose (0 :: Int, 3)       case constructorIndex of         0 -> return Empty         1 -> C.arbitrary >>= return . Singleton         2 -> C.arbitrary >>= return . Vector+        3 -> C.arbitrary >>= return . List
vector-builder.cabal view
@@ -1,7 +1,7 @@ name:   vector-builder version:-  0.3.7+  0.3.7.1 synopsis:   Vector builder description:@@ -79,7 +79,7 @@     vector >=0.11 && <0.13,     semigroups >=0.16 && <0.20,     base-prelude <2,-    base >=4.6 && <5+    base >=4.8 && <5  test-suite tests   type: