mirror of
https://github.com/simplex-chat/haskell.nix.git
synced 2026-06-03 09:17:32 +00:00
20 lines
638 B
Haskell
20 lines
638 B
Haskell
-- https://github.com/snoyberg/conduit#readme
|
|
|
|
import Conduit
|
|
import System.Directory (removeFile)
|
|
|
|
main = do
|
|
-- Pure operations: summing numbers.
|
|
print $ runConduitPure $ yieldMany [1..10] .| sumC
|
|
|
|
-- Exception safe file access: copy a file.
|
|
writeFile "input.txt" "This is a test." -- create the source file
|
|
runConduitRes $ sourceFileBS "input.txt" .| sinkFile "output.txt" -- actual copying
|
|
readFile "output.txt" >>= putStrLn -- prove that it worked
|
|
|
|
-- Perform transformations.
|
|
print $ runConduitPure $ yieldMany [1..10] .| mapC (+ 1) .| sinkList
|
|
|
|
removeFile "input.txt"
|
|
removeFile "output.txt"
|