mirror of
https://github.com/ilyakooo0/haskell.nix.git
synced 2024-09-11 06:55:40 +03: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"
|