Created
May 12, 2018 10:30
-
-
Save danidiaz/691a84505adf4fcd26b5cb020bacecd8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Foldable (toList) | |
import Streaming | |
import qualified Streaming.Prelude as S | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
main :: IO () | |
main = | |
withFile "/tmp/source.txt" ReadMode $ \hSource -> | |
withFile "/tmp/target.txt" WriteMode $ \hTarget -> | |
S.mapM_ (TIO.hPutStrLn hTarget) | |
. flip S.for S.each | |
. S.filter (\window -> toList window == [T.pack "4",T.pack "6"]) | |
. S.slidingWindow 2 | |
. S.untilRight | |
$ do atEof <- hIsEOF hSource | |
if atEof | |
then Right <$> pure () | |
else Left <$> TIO.hGetLine hSource |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment