import Control.Monad
import System.Environment
import Control.Monad.IO.Class (liftIO)
import System.IO
import Data.Conduit.Lazy
import Data.List (sort)

import Data.Conduit

import Prelude hiding (map)

main = getArgs >>= process

process args = mapM_ sorted args

sorted x = runResourceT (lazyConsume $ sourceFeed x) >>= (mapM_ print . id)

sourceFeed :: ResourceIO m => FilePath -> Source m String
sourceFeed file = sourceIO
    (openFile file ReadMode)
    hClose
    (\h -> liftIO $ do
        eof <- hIsEOF h
        if eof
            then return IOClosed
            else fmap IOOpen $ hGetLine h)
