packages feed

mono-traversable 0.6.0.4 → 0.6.1

raw patch · 3 files changed

+37/−1 lines, 3 files

Files

mono-traversable.cabal view
@@ -1,5 +1,5 @@ name:                mono-traversable-version:             0.6.0.4+version:             0.6.1 synopsis:            Type classes for mapping, folding, and traversing monomorphic containers description:         Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. Contains even more experimental code for abstracting containers and sequences. homepage:            https://github.com/snoyberg/mono-traversable@@ -19,6 +19,7 @@                        Data.Sequences                        Data.NonNull                        Data.MinLen+                       Data.ByteVector   other-modules:       Data.GrowingAppend   build-depends:       base >= 4 && < 5                      , containers >= 0.4
+ src/Data/ByteVector.hs view
@@ -0,0 +1,28 @@+-- | Provides conversion functions between strict @ByteString@s and storable+-- @Vector@s.+module Data.ByteVector+    ( toByteVector+    , fromByteVector+    ) where++import           Data.ByteString.Internal (ByteString (PS))+import           Data.Vector.Storable     (Vector, unsafeFromForeignPtr,+                                           unsafeToForeignPtr)+import           Data.Word                (Word8)++-- | Convert a @ByteString@ into a storable @Vector@.+--+-- Since 0.6.1+toByteVector :: ByteString -> Vector Word8+toByteVector (PS fptr offset idx) = unsafeFromForeignPtr fptr offset idx+{-# INLINE toByteVector #-}++-- | Convert a storable @Vector@ into a @ByteString@.+--+-- Since 0.6.1+fromByteVector :: Vector Word8 -> ByteString+fromByteVector v =+    PS fptr offset idx+  where+    (fptr, offset, idx) = unsafeToForeignPtr v+{-# INLINE fromByteVector #-}
test/Spec.hs view
@@ -31,6 +31,7 @@ import Control.Arrow (first, second) import qualified Control.Foldl as Foldl import Data.Int (Int64)+import Data.ByteVector  main :: IO () main = hspec $ do@@ -313,3 +314,9 @@      it "find doesn't infinitely loop on NonEmpty #31" $         find (== "a") ("a" NE.:| ["d","fgf"]) `shouldBe` Just "a"++    prop "toByteVector works" $ \ws ->+        (otoList . toByteVector . fromList $ ws) `shouldBe` ws++    prop "fromByteVector works" $ \ws ->+        (otoList . fromByteVector . fromList $ ws) `shouldBe` ws