2-- Module : Streamly.Internal.Unicode.Array
3-- Copyright : (c) 2018 Composewell Technologies
5-- License : BSD-3-Clause
6-- Maintainer : streamly@composewell.com
7-- Stability : experimental
10-- XXX Remove this or move this to Unicode.Utf32 making "Array Char" as a
11-- newtype wrapper for Utf32. Is this any better than the [Char] (String) type?
12-- This provides random access and the length of the string in O(1). Also,
13-- better append performance.
15module Streamly.Internal.Unicode.Array
18 -- | To execute the code examples provided in this module in ghci, please
19 -- run the following commands first.
23 -- * Streams of Strings
31import Control.Monad.IO.Class (MonadIO)
32import Streamly.Data.Stream (Stream)
33import Streamly.Internal.Data.Array (Array)
35import qualified Streamly.Data.Array as A
36import qualified Streamly.Internal.Unicode.Stream as S
38import Prelude hiding (String, lines, words, unlines, unwords)
42-- >>> :set -XOverloadedStrings
43-- >>> import Prelude hiding (String, lines, words, unlines, unwords)
44-- >>> import qualified Streamly.Data.Stream as Stream
45-- >>> import qualified Streamly.Data.Fold as Fold
46-- >>> import qualified Streamly.Internal.Unicode.Array as Unicode
48-- | Break a string up into a stream of strings at newline characters.
49-- The resulting strings do not contain newlines.
51-- > lines = S.lines A.write
53-- >>> Stream.fold Fold.toList $ Unicode.lines $ Stream.fromList "lines\nthis\nstring\n\n\n"
54-- [fromList "lines",fromList "this",fromList "string",fromList "",fromList ""]
57lines :: MonadIO m => Stream m Char -> Stream m (Array Char)
58lines = S.lines A.write
60-- | Break a string up into a stream of strings, which were delimited
61-- by characters representing white space.
63-- > words = S.words A.write
65-- >>> Stream.fold Fold.toList $ Unicode.words $ Stream.fromList "A newline\nis considered white space?"
66-- [fromList "A",fromList "newline",fromList "is",fromList "considered",fromList "white",fromList "space?"]
69words :: MonadIO m => Stream m Char -> Stream m (Array Char)
70words = S.words A.write
72-- | Flattens the stream of @Array Char@, after appending a terminating
73-- newline to each string.
75-- 'unlines' is an inverse operation to 'lines'.
77-- >>> Stream.fold Fold.toList $ Unicode.unlines $ Stream.fromList ["lines", "this", "string"]
78-- "lines\nthis\nstring\n"
80-- > unlines = S.unlines A.read
82-- Note that, in general
84-- > unlines . lines /= id
86unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char
87unlines = S.unlines A.reader
89-- | Flattens the stream of @Array Char@, after appending a separating
90-- space to each string.
92-- 'unwords' is an inverse operation to 'words'.
94-- >>> Stream.fold Fold.toList $ Unicode.unwords $ Stream.fromList ["unwords", "this", "string"]
95-- "unwords this string"
97-- > unwords = S.unwords A.read
99-- Note that, in general
101-- > unwords . words /= id
102{-# INLINE unwords #-}
103unwords :: MonadIO m => Stream m (Array Char) -> Stream m Char
104unwords = S.unwords A.reader
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list