on master help sign in
Deprecate Streamly.Data.Unicode.Stream
7d00819adithyaov
Changelog.md+1
@@ -2,6 +2,7 @@
2
2
3### Breaking changes
3### Breaking changes
4
4
5+* Deprecate `Streamly.Data.Unicode.Stream` in favor of `Streamly.Unicode.Stream`
5* Change the signature of `foldlM'` to make the initial value of the
6* Change the signature of `foldlM'` to make the initial value of the
6 accumulator monadic.
7 accumulator monadic.
7* Change the signature of `concatMapWith` to ensure that it can be
8* Change the signature of `concatMapWith` to ensure that it can be
benchmark/Streamly/Benchmark/FileSystem/Handle/Read.hs+1−1
@@ -36,7 +36,7 @@ import System.IO (Handle)
36import Prelude hiding (last, length)
36import Prelude hiding (last, length)
37
37
38import qualified Streamly.Data.Fold as FL
38import qualified Streamly.Data.Fold as FL
39−import qualified Streamly.Data.Unicode.Stream as SS
39+import qualified Streamly.Unicode.Stream as SS
40import qualified Streamly.FileSystem.Handle as FH
40import qualified Streamly.FileSystem.Handle as FH
41-- import qualified Streamly.Internal.Data.Fold as IFL
41-- import qualified Streamly.Internal.Data.Fold as IFL
42import qualified Streamly.Internal.Data.Parser as PR
42import qualified Streamly.Internal.Data.Parser as PR
benchmark/Streamly/Benchmark/FileSystem/Handle/ReadWrite.hs+1−1
@@ -28,7 +28,7 @@ import System.IO (Handle, hClose)
28import Prelude hiding (last, length)
28import Prelude hiding (last, length)
29
29
30import qualified Streamly.Data.Fold as FL
30import qualified Streamly.Data.Fold as FL
31−import qualified Streamly.Data.Unicode.Stream as SS
31+import qualified Streamly.Unicode.Stream as SS
32import qualified Streamly.FileSystem.Handle as FH
32import qualified Streamly.FileSystem.Handle as FH
33import qualified Streamly.Internal.Data.Unfold as IUF
33import qualified Streamly.Internal.Data.Unfold as IUF
34import qualified Streamly.Internal.Unicode.Stream as IUS
34import qualified Streamly.Internal.Unicode.Stream as IUS
examples/FileSinkServer.hs+1−1
@@ -10,7 +10,7 @@ import Network.Socket (close)
10import System.Environment (getArgs)
10import System.Environment (getArgs)
11
11
12import Streamly
12import Streamly
13−import Streamly.Data.Unicode.Stream
13+import Streamly.Unicode.Stream
14import qualified Streamly.FileSystem.Handle as FH
14import qualified Streamly.FileSystem.Handle as FH
15import qualified Streamly.Memory.Array as A
15import qualified Streamly.Memory.Array as A
16import qualified Streamly.Network.Socket as NS
16import qualified Streamly.Network.Socket as NS
examples/WordClassifier.hs+1−1
@@ -16,7 +16,7 @@ import Data.IORef
16import qualified Data.List as List
16import qualified Data.List as List
17import qualified Data.Ord as Ord
17import qualified Data.Ord as Ord
18import Foreign.Storable (Storable(..))
18import Foreign.Storable (Storable(..))
19−import qualified Streamly.Data.Unicode.Stream as S
19+import qualified Streamly.Unicode.Stream as S
20import qualified Streamly.Internal.Unicode.Stream as S
20import qualified Streamly.Internal.Unicode.Stream as S
21import qualified Streamly.Data.Fold as FL
21import qualified Streamly.Data.Fold as FL
22import qualified Streamly.Internal.Data.Fold as IFL
22import qualified Streamly.Internal.Data.Fold as IFL
examples/WordCount.hs+1−1
@@ -41,7 +41,7 @@ import Streamly.Internal.Unicode.Stream
41 resumeDecodeUtf8Either)
41 resumeDecodeUtf8Either)
42
42
43import qualified Streamly as S
43import qualified Streamly as S
44−import qualified Streamly.Data.Unicode.Stream as S
44+import qualified Streamly.Unicode.Stream as S
45import qualified Streamly.FileSystem.Handle as FH
45import qualified Streamly.FileSystem.Handle as FH
46import qualified Streamly.Memory.Array as A
46import qualified Streamly.Memory.Array as A
47import qualified Streamly.Prelude as S
47import qualified Streamly.Prelude as S
src/Streamly/Data/Unicode/Stream.hs+1
@@ -65,6 +65,7 @@
65-- lived strings in memory.
65-- lived strings in memory.
66--
66--
67module Streamly.Data.Unicode.Stream
67module Streamly.Data.Unicode.Stream
68+ {-# DEPRECATED "Use Streamly.Unicode.Stream instead" #-}
68 (
69 (
69 -- * Construction (Decoding)
70 -- * Construction (Decoding)
70 decodeLatin1
71 decodeLatin1
src/Streamly/Unicode/Stream.hsnew file+96
@@ -0,0 +1,96 @@
1+-- |
2+-- Module : Streamly.Unicode.Stream
3+-- Copyright : (c) 2020 Composewell Technologies
4+--
5+-- License : BSD-3-Clause
6+-- Maintainer : streamly@composewell.com
7+-- Stability : experimental
8+-- Portability : GHC
9+--
10+-- = Processing Unicode Strings
11+--
12+-- A 'Char' stream is the canonical representation to process Unicode strings.
13+-- It can be processed efficiently using regular stream processing operations.
14+-- A byte stream of Unicode text read from an IO device or from an
15+-- 'Streamly.Memory.Array.Array' in memory can be decoded into a 'Char' stream
16+-- using the decoding routines in this module. A 'String' (@[Char]@) can be
17+-- converted into a 'Char' stream using 'Streamly.Prelude.fromList'. An @Array
18+-- Char@ can be 'Streamly.Prelude.unfold'ed into a stream using the array
19+-- 'Streamly.Memory.Array.read' unfold.
20+--
21+-- = Storing Unicode Strings
22+--
23+-- A stream of 'Char' can be encoded into a byte stream using the encoding
24+-- routines in this module and then written to IO devices or to arrays in
25+-- memory.
26+--
27+-- If you have to store a 'Char' stream in memory you can convert it into a
28+-- 'String' using 'Streamly.Prelude.toList' or using the
29+-- 'Streamly.Data.Fold.toList' fold. The 'String' type can be more efficient
30+-- than pinned arrays for short and short lived strings.
31+--
32+-- For longer or long lived streams you can 'Streamly.Prelude.fold' the 'Char'
33+-- stream as @Array Char@ using the array 'Streamly.Memory.Array.write' fold.
34+-- The 'Array' type provides a more compact representation and pinned memory
35+-- reducing GC overhead. If space efficiency is a concern you can use
36+-- 'encodeUtf8' on the 'Char' stream before writing it to an 'Array' providing
37+-- an even more compact representation.
38+--
39+-- = String Literals
40+--
41+-- @SerialT Identity Char@ and @Array Char@ are instances of 'IsString' and
42+-- 'IsList', therefore, 'OverloadedStrings' and 'OverloadedLists' extensions
43+-- can be used for convenience when specifying unicode strings literals using
44+-- these types.
45+--
46+-- = Pitfalls
47+--
48+-- * Case conversion: Some unicode characters translate to more than one code
49+-- point on case conversion. The 'toUpper' and 'toLower' functions in @base@
50+-- package do not handle such characters. Therefore, operations like @map
51+-- toUpper@ on a character stream or character array may not always perform
52+-- correct conversion.
53+-- * String comparison: In some cases, visually identical strings may have
54+-- different unicode representations, therefore, a character stream or
55+-- character array cannot be directly compared. A normalized comparison may be
56+-- needed to check string equivalence correctly.
57+--
58+-- = Experimental APIs
59+--
60+-- Some experimental APIs to conveniently process text using the
61+-- @Array Char@ represenation directly can be found in
62+-- "Streamly.Internal.Memory.Unicode.Array".
63+
64+-- XXX an unpinned array representation can be useful to store short and short
65+-- lived strings in memory.
66+--
67+module Streamly.Unicode.Stream
68+ (
69+ -- * Construction (Decoding)
70+ decodeLatin1
71+ , decodeUtf8
72+ , decodeUtf8Lax
73+
74+ -- * Elimination (Encoding)
75+ , encodeLatin1
76+ , encodeLatin1Lax
77+ , encodeUtf8
78+ , encodeUtf8Lax
79+ {-
80+ -- * Operations on character strings
81+ , strip -- (dropAround isSpace)
82+ , stripEnd
83+ , stripStart
84+ -}
85+ -- Not exposing these yet as we have consider these with respect to Unicode
86+ -- segmentation routines which are yet to be implemented.
87+ -- -- * Transformation
88+ -- , lines
89+ -- , words
90+ -- , unlines
91+ -- , unwords
92+ )
93+where
94+
95+import Streamly.Internal.Unicode.Stream
96+import Prelude hiding (lines, words, unlines, unwords)
streamly.cabal+4−1
@@ -388,7 +388,9 @@ library
388 , Streamly
388 , Streamly
389 , Streamly.Data.Fold
389 , Streamly.Data.Fold
390 , Streamly.Data.Unfold
390 , Streamly.Data.Unfold
391+
392+ -- Text Processing
391− , Streamly.Data.Unicode.Stream
393+ , Streamly.Unicode.Stream
392
394
393 -- IO devices
395 -- IO devices
394 , Streamly.Memory.Array
396 , Streamly.Memory.Array
@@ -489,6 +491,7 @@ library
489 , Streamly.Internal.Data.Binary.Decode
491 , Streamly.Internal.Data.Binary.Decode
490
492
491 -- Deprecated
493 -- Deprecated
494+ , Streamly.Data.Unicode.Stream
492
495
493 if !impl(ghcjs)
496 if !impl(ghcjs)
494 exposed-modules:
497 exposed-modules:
test/Streamly/Test/FileSystem/Event.hs+1−1
@@ -20,7 +20,7 @@ import System.Environment (getArgs)
20import Streamly (SerialT)
20import Streamly (SerialT)
21
21
22import qualified Data.List.NonEmpty as NonEmpty
22import qualified Data.List.NonEmpty as NonEmpty
23−import qualified Streamly.Data.Unicode.Stream as Unicode
23+import qualified Streamly.Unicode.Stream as Unicode
24import qualified Streamly.Internal.Data.Stream.IsStream as Stream
24import qualified Streamly.Internal.Data.Stream.IsStream as Stream
25#if defined(CABAL_OS_DARWIN)
25#if defined(CABAL_OS_DARWIN)
26import qualified Streamly.Internal.FileSystem.Event.Darwin as Event
26import qualified Streamly.Internal.FileSystem.Event.Darwin as Event
test/String.hs+1−1
@@ -12,7 +12,7 @@ import Test.Hspec as H
12import qualified Streamly.Memory.Array as A
12import qualified Streamly.Memory.Array as A
13import qualified Streamly.Internal.Memory.ArrayStream as AS
13import qualified Streamly.Internal.Memory.ArrayStream as AS
14import qualified Streamly.Prelude as S
14import qualified Streamly.Prelude as S
15−import qualified Streamly.Data.Unicode.Stream as SS
15+import qualified Streamly.Unicode.Stream as SS
16import qualified Streamly.Internal.Unicode.Stream as IUS
16import qualified Streamly.Internal.Unicode.Stream as IUS
17import qualified Streamly.Internal.Memory.Unicode.Array as IUA
17import qualified Streamly.Internal.Memory.Unicode.Array as IUA
18
18