{-| Module: Line Description: Arbitrary Text Line. Copyright: © 2017 All rights reserved. License: GPL-3 Maintainer: Evan Cofsky Stability: experimental Portability: POSIX -} module Line (Line(..), readWriteLines) where import Lawless hiding (mapping) import Textual import Arbitrary() import Test.QuickCheck import Text import Text.IO import IO hiding (putStrLn) import Machine import Path newtype Line = Line Text deriving (Eq, Ord, Show) instance Arbitrary Line where arbitrary = Line <$> suchThat arbitrary (allOf each (≥ ' ')) instance Printable Line where print (Line t) = print t readWriteLines ∷ (Traversable f, MonadMask m, MonadIO m) ⇒ f Line → m [Line] readWriteLines lns = textTemporaryFile (absDir "/tmp") (relFile "testTemp") $ \tf → do let h = tf ^. tfHandle runT_ $ supply lns (mapping $ \(Line t) → t) ⇝ writeLines h ⇝ autoM (\l → putStrLn l ≫ return l) runT $ readLines h ⇝ autoM (\l → putStrLn l ≫ return l) ⇝ mapping Line