streamly-core-0.2.0: Streaming, parsers, arrays and more
Copyright(c) 2018 Composewell Technologies
LicenseBSD-3-Clause
Maintainerstreamly@composewell.com
Stabilityexperimental
PortabilityGHC
Safe HaskellSafe-Inferred
LanguageHaskell2010

Streamly.Internal.Unicode.Array

Description

 
Synopsis

Setup

To execute the code examples provided in this module in ghci, please run the following commands first.

>>> :m
>>> :set -XOverloadedStrings
>>> import Prelude hiding (String, lines, words, unlines, unwords)
>>> import qualified Streamly.Data.Stream as Stream
>>> import qualified Streamly.Data.Fold as Fold
>>> import qualified Streamly.Internal.Unicode.Array as Unicode

Streams of Strings

lines :: MonadIO m => Stream m Char -> Stream m (Array Char) Source #

Break a string up into a stream of strings at newline characters. The resulting strings do not contain newlines.

lines = S.lines A.write
>>> Stream.fold Fold.toList $ Unicode.lines $ Stream.fromList "lines\nthis\nstring\n\n\n"
[fromList "lines",fromList "this",fromList "string",fromList "",fromList ""]

words :: MonadIO m => Stream m Char -> Stream m (Array Char) Source #

Break a string up into a stream of strings, which were delimited by characters representing white space.

words = S.words A.write
>>> Stream.fold Fold.toList $ Unicode.words $ Stream.fromList "A  newline\nis considered white space?"
[fromList "A",fromList "newline",fromList "is",fromList "considered",fromList "white",fromList "space?"]

unlines :: MonadIO m => Stream m (Array Char) -> Stream m Char Source #

Flattens the stream of Array Char, after appending a terminating newline to each string.

unlines is an inverse operation to lines.

>>> Stream.fold Fold.toList $ Unicode.unlines $ Stream.fromList ["lines", "this", "string"]
"lines\nthis\nstring\n"
unlines = S.unlines A.read

Note that, in general

unlines . lines /= id

unwords :: MonadIO m => Stream m (Array Char) -> Stream m Char Source #

Flattens the stream of Array Char, after appending a separating space to each string.

unwords is an inverse operation to words.

>>> Stream.fold Fold.toList $ Unicode.unwords $ Stream.fromList ["unwords", "this", "string"]
"unwords this string"
unwords = S.unwords A.read

Note that, in general

unwords . words /= id