module Text.Madlibs.Internal.Utils where
import Text.Madlibs.Internal.Types
import Text.Megaparsec.Text
import Text.Megaparsec.Error
import qualified Data.Text as T
import System.IO.Unsafe
(.$) :: (a -> a -> b) -> a -> b
(.$) f x = f x x
instance (Monoid a) => Monoid (Parser a) where
mempty = pure mempty
mappend x y = mappend <$> x <*> y
cdf :: [Prob] -> [Prob]
cdf = (drop 2) . (scanl (+) 0) . ((:) 0)
show' :: (Show a) => a -> T.Text
show' = (T.drop 1) . T.init . T.pack . show
parseErrorPretty' :: ParseError Char Dec -> T.Text
parseErrorPretty' = T.pack . parseErrorPretty
unTok :: PreTok -> T.Text
unTok (PreTok txt) = ""
unTok (Name txt) = txt
readFile' :: FilePath -> IO T.Text
readFile' = (fmap T.pack) . readFile