X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=Pipes%2FText%2FTutorial.hs;h=d7ff703dde9a21fbe4157b97aafe0e43ac8fcf65;hb=5dca0cf23401438e53f88a216b65d5e983bc9292;hp=eeaafa7d6d18471dc7448c7c1091254043ceb256;hpb=d19efff3b167122a83f5c269fd6ecb8cf9c78f33;p=github%2Ffretlink%2Ftext-pipes.git diff --git a/Pipes/Text/Tutorial.hs b/Pipes/Text/Tutorial.hs index eeaafa7..d7ff703 100644 --- a/Pipes/Text/Tutorial.hs +++ b/Pipes/Text/Tutorial.hs @@ -84,7 +84,7 @@ import Pipes.Text.Encoding in a way that is independent of the boundaries of the underlying @Text@ chunks. This means that they may freely split text into smaller texts and /discard empty texts/. The objective, though, is that they should not /concatenate texts/ in order to provide strict upper - bounds on memory usage. + bounds on memory usage even for indefinitely complex compositions. For example, to stream only the first three lines of 'stdin' to 'stdout' you might write: @@ -93,12 +93,12 @@ import Pipes.Text.Encoding > import qualified Pipes.Text as Text > import qualified Pipes.Text.IO as Text > import Pipes.Group (takes') -> import Lens.Family (view, (%~)) -- or, Control.Lens +> import Lens.Family (view, over) -- or `Lens.Micro.Mtl` or `Control.Lens` or etc. > > main = runEffect $ takeLines 3 Text.stdin >-> Text.stdout > where > takeLines n = view Text.unlines . takes' n . view Text.lines -> -- or equivalently: Text.unlines %~ takes' n +> -- or equivalently: over Text.unlines (takes' n) This program will not bring more into memory than what @Text.stdin@ considers one chunk of text (~ 32 KB), even if individual lines are split