list-t-text (empty) → 0.1.0.1
raw patch · 5 files changed
+161/−0 lines, 5 filesdep +QuickCheckdep +base-preludedep +bytestringsetup-changed
Dependencies added: QuickCheck, base-prelude, bytestring, hspec, list-t, list-t-text, mtl-prelude, quickcheck-instances, text, transformers
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- hspec/Main.hs +27/−0
- library/ListT/Text.hs +26/−0
- list-t-text.cabal +84/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2015, Nikita Volkov++Permission is hereby granted, free of charge, to any person+obtaining a copy of this software and associated documentation+files (the "Software"), to deal in the Software without+restriction, including without limitation the rights to use,+copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the+Software is furnished to do so, subject to the following+conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR+OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ hspec/Main.hs view
@@ -0,0 +1,27 @@+import BasePrelude+import Test.Hspec+import Test.QuickCheck+import Test.QuickCheck.Instances+import Data.Text (Text)+import Data.ByteString (ByteString)+import qualified Data.Text.Encoding as TE+import qualified ListT as L+import ListT.Text+import qualified Data.ByteString as B+import Data.Functor.Identity+++main = + hspec $ do+ context "utf8ByteString" $ do+ it "back and forth" $+ property $ \text ->+ TE.encodeUtf8 text & streamByteString 3 & utf8ByteString & L.toList & runIdentity & mconcat &+ (==) text++streamByteString :: Monad m => Int -> ByteString -> L.ListT m ByteString+streamByteString n b =+ B.splitAt n b & \(l, r) -> + if B.null l+ then mzero+ else L.cons l (streamByteString n r)
+ library/ListT/Text.hs view
@@ -0,0 +1,26 @@+module ListT.Text where++import BasePrelude hiding (cons, uncons)+import MTLPrelude+import ListT+import Data.ByteString (ByteString)+import Data.Text (Text)+import qualified Data.Text.Encoding as TE+import qualified Data.Text as T+import qualified Data.ByteString as B+++-- |+-- A transformation of a stream of byte-strings +-- to a stream of text chunks decoded using UTF-8.+utf8ByteString :: Monad m => Transformation m ByteString Text+utf8ByteString =+ loop TE.streamDecodeUtf8+ where+ loop decode stream =+ lift (uncons stream) >>= \case+ Nothing -> mzero+ Just (chunk, stream') -> + decode chunk & \(TE.Some result leftover decode') ->+ bool (cons result) id (T.null result) (loop decode' stream')+
+ list-t-text.cabal view
@@ -0,0 +1,84 @@+name:+ list-t-text+version:+ 0.1.0.1+synopsis:+ A streaming text codec+category:+ Streaming, HTTP, Codec+homepage:+ https://github.com/nikita-volkov/list-t-text+bug-reports:+ https://github.com/nikita-volkov/list-t-text/issues +author:+ Nikita Volkov <nikita.y.volkov@mail.ru>+maintainer:+ Nikita Volkov <nikita.y.volkov@mail.ru>+copyright:+ (c) 2015, Nikita Volkov+license:+ MIT+license-file:+ LICENSE+build-type:+ Simple+cabal-version:+ >=1.10+++source-repository head+ type:+ git+ location:+ git://github.com/nikita-volkov/list-t-text.git+++library+ hs-source-dirs:+ library+ other-modules:+ exposed-modules:+ ListT.Text+ ghc-options:+ -funbox-strict-fields+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators+ default-language:+ Haskell2010+ build-depends:+ bytestring >= 0.10 && < 0.11,+ text >= 1 && < 1.3,+ list-t == 0.4.*,+ mtl-prelude >= 1 && < 3,+ base-prelude >= 0.1.19 && < 0.2+++test-suite hspec+ type:+ exitcode-stdio-1.0+ hs-source-dirs:+ hspec+ main-is:+ Main.hs+ ghc-options:+ -threaded+ "-with-rtsopts=-N"+ -funbox-strict-fields+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators+ default-language:+ Haskell2010+ build-depends:+ -- + hspec == 2.1.*,+ QuickCheck >= 2.6 && < 2.8,+ quickcheck-instances,+ -- + text,+ bytestring,+ -- + list-t-text,+ list-t,+ transformers,+ -- + base-prelude