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
17 -- * Streams of Strings
25import Control.Monad.IO.Class (MonadIO)
26import Streamly.Data.Stream (Stream)
27import Streamly.Internal.Data.Array (Array)
29import qualified Streamly.Data.Array as A
30import qualified Streamly.Internal.Unicode.Stream as S
32import Prelude hiding (String, lines, words, unlines, unwords)
36-- >>> :set -XOverloadedStrings
37-- >>> import Prelude hiding (String, lines, words, unlines, unwords)
38-- >>> import qualified Streamly.Data.Stream as Stream
39-- >>> import qualified Streamly.Data.Fold as Fold
40-- >>> import qualified Streamly.Internal.Unicode.Array as Unicode
42-- | Break a string up into a stream of strings at newline characters.
43-- The resulting strings do not contain newlines.
45-- > lines = S.lines A.write
47-- >>> Stream.fold Fold.toList $ Unicode.lines $ Stream.fromList "lines\nthis\nstring\n\n\n"
48-- [fromList "lines",fromList "this",fromList "string",fromList "",fromList ""]
51lines :: MonadIO m => Stream m Char -> Stream m (Array Char)
52lines = S.lines A.write
54-- | Break a string up into a stream of strings, which were delimited
55-- by characters representing white space.
57-- > words = S.words A.write
59-- >>> Stream.fold Fold.toList $ Unicode.words $ Stream.fromList "A newline\nis considered white space?"
60-- [fromList "A",fromList "newline",fromList "is",fromList "considered",fromList "white",fromList "space?"]
63words :: MonadIO m => Stream m Char -> Stream m (Array Char)
64words = S.words A.write
66-- | Flattens the stream of @Array Char@, after appending a terminating
67-- newline to each string.
69-- 'unlines' is an inverse operation to 'lines'.
71-- >>> Stream.fold Fold.toList $ Unicode.unlines $ Stream.fromList ["lines", "this", "string"]
72-- "lines\nthis\nstring\n"
74-- > unlines = S.unlines A.read
76-- Note that, in general
78-- > unlines . lines /= id
80unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char
81unlines = S.unlines A.reader
83-- | Flattens the stream of @Array Char@, after appending a separating
84-- space to each string.
86-- 'unwords' is an inverse operation to 'words'.
88-- >>> Stream.fold Fold.toList $ Unicode.unwords $ Stream.fromList ["unwords", "this", "string"]
89-- "unwords this string"
91-- > unwords = S.unwords A.read
93-- Note that, in general
95-- > unwords . words /= id
97unwords :: MonadIO m => Stream m (Array Char) -> Stream m Char
98unwords = 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