Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Created May 12, 2018 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danidiaz/691a84505adf4fcd26b5cb020bacecd8 to your computer and use it in GitHub Desktop.
Save danidiaz/691a84505adf4fcd26b5cb020bacecd8 to your computer and use it in GitHub Desktop.
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