papa-0.7.0: test/Totals.hs
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wall #-}
{- HLINT ignore "Avoid restricted function" -}
-- Reason: these are Papa's total head, last, init, tail, (!!), maximum and
-- minimum, whose names HLint restricts whatever module they come from.
-- | The total types of the names that 'Papa' reuses from "Prelude" and base
-- for a total function.
--
-- Each binding uses one such name at its total type. Were 'Papa' to export
-- the partial function of that name again (@head :: [a] -> a@,
-- @succ :: a -> a@, a lazy @readFile@, …), the binding would not type check,
-- and this module, and so the test suite, would not compile. That is the
-- test. "Deny" covers the names that 'Papa' must not export at all.
module Totals (
totals,
readFileOfPath,
writeFileOfPath,
appendFileOfPath,
getContentsOfStdin,
getLineOfStdin,
interactOfStdin,
putStrOfText,
putStrLnOfText,
printOfInt,
hGetContentsOfHandle,
hGetLineOfHandle,
hPutStrOfHandle,
hPutStrLnOfHandle,
hPrintOfHandle,
openFileOfPath,
withFileOfPath,
hCloseOfHandle,
hFlushOfHandle,
hIsEOFOfHandle,
hSetBufferingOfHandle,
exitWithOfCode,
doesFileExistOfPath,
listDirectoryOfPath,
createDirectoryOfPath,
removeFileOfPath,
copyFileOfPaths,
getCurrentDirectoryOfProcess,
getTemporaryDirectoryOfProcess,
withCurrentDirectoryOfPath,
getSearchPathOfProcess,
waitExceptOfAsync,
waitAnyCatchOfNonEmpty,
waitAnyCatchCancelOfNonEmpty,
readIOOfText,
dieOfText,
) where
import Papa
-- | One use of each reused name at its total type.
totals :: [String]
totals =
[ show (headOfNonEmpty (1 :| [2]))
, show (lastOfNonEmpty (1 :| [2]))
, show (initOfNonEmpty (1 :| [2]))
, show (tailOfNonEmpty (1 :| [2]))
, show (indexOfList [1, 2] 5)
, show (maximumOfNonEmpty (1 :| [2]))
, show (minimumOfNonEmpty (1 :| [2]))
, show (maximumByOfNonEmpty compare (1 :| [2]))
, show (minimumByOfNonEmpty compare (1 :| [2]))
, show (cycleOfList [])
, show (chrOfInt (-1))
, show (succOfInt maxBound)
, show (predOfInt minBound)
, show (stimesOfList (-1) [1])
, show (cycleOfList [1])
, show (lookupOfList 1 [(1, 'a')])
, show (iterateOfInt (+ 1) 0 ^? ix 3)
, show (repeatOfInt 1 ^? ix 3)
, show (linesOfText (pack "a\nb"))
, show (wordsOfText (pack "a b"))
, show (readMaybeOfText (pack "1"))
, show (readEitherOfText (pack "1"))
]
headOfNonEmpty :: NonEmpty Int -> Int
headOfNonEmpty =
the head
lastOfNonEmpty :: NonEmpty Int -> Int
lastOfNonEmpty =
the last
initOfNonEmpty :: NonEmpty Int -> [Int]
initOfNonEmpty =
the init
tailOfNonEmpty :: NonEmpty Int -> [Int]
tailOfNonEmpty =
the tail
indexOfList :: [Int] -> Int -> Maybe Int
indexOfList =
(!!)
maximumOfNonEmpty :: NonEmpty Int -> Int
maximumOfNonEmpty =
maximum
minimumOfNonEmpty :: NonEmpty Int -> Int
minimumOfNonEmpty =
minimum
maximumByOfNonEmpty :: (Int -> Int -> Ordering) -> NonEmpty Int -> Int
maximumByOfNonEmpty =
maximumBy
minimumByOfNonEmpty :: (Int -> Int -> Ordering) -> NonEmpty Int -> Int
minimumByOfNonEmpty =
minimumBy
cycleOfList :: [Int] -> Maybe [Int]
cycleOfList =
fmap (take 3) . cycle
chrOfInt :: Int -> Maybe Char
chrOfInt =
chr
succOfInt :: Int -> Maybe Int
succOfInt =
succ
predOfInt :: Int -> Maybe Int
predOfInt =
pred
stimesOfList :: Int -> [Int] -> Maybe [Int]
stimesOfList =
stimes
lookupOfList :: Int -> [(Int, Char)] -> Maybe Char
lookupOfList =
lookup
iterateOfInt :: (Int -> Int) -> Int -> NonEmpty Int
iterateOfInt =
iterate
repeatOfInt :: Int -> NonEmpty Int
repeatOfInt =
repeat
linesOfText :: Text -> [Text]
linesOfText =
lines
wordsOfText :: Text -> [Text]
wordsOfText =
words
-- I/O: strict, UTF-8, and returning its errors.
readFileOfPath :: FilePath -> IOExcept Text
readFileOfPath =
readFile
writeFileOfPath :: FilePath -> Text -> IOExcept ()
writeFileOfPath =
writeFile
appendFileOfPath :: FilePath -> Text -> IOExcept ()
appendFileOfPath =
appendFile
getContentsOfStdin :: IOExcept Text
getContentsOfStdin =
getContents
getLineOfStdin :: IOExcept Text
getLineOfStdin =
getLine
interactOfStdin :: (Text -> Text) -> IOExcept ()
interactOfStdin =
interact
putStrOfText :: Text -> IOExcept ()
putStrOfText =
putStr
putStrLnOfText :: Text -> IOExcept ()
putStrLnOfText =
putStrLn
printOfInt :: Int -> IOExcept ()
printOfInt =
print
hGetContentsOfHandle :: Handle -> IOExcept Text
hGetContentsOfHandle =
hGetContents
hGetLineOfHandle :: Handle -> IOExcept Text
hGetLineOfHandle =
hGetLine
hPutStrOfHandle :: Handle -> Text -> IOExcept ()
hPutStrOfHandle =
hPutStr
hPutStrLnOfHandle :: Handle -> Text -> IOExcept ()
hPutStrLnOfHandle =
hPutStrLn
hPrintOfHandle :: Handle -> Int -> IOExcept ()
hPrintOfHandle =
hPrint
openFileOfPath :: FilePath -> IOMode -> IOExcept Handle
openFileOfPath =
openFile
withFileOfPath :: FilePath -> IOMode -> (Handle -> IOExcept Text) -> IOExcept Text
withFileOfPath =
withFile
hCloseOfHandle :: Handle -> IOExcept ()
hCloseOfHandle =
hClose
hFlushOfHandle :: Handle -> IOExcept ()
hFlushOfHandle =
hFlush
hIsEOFOfHandle :: Handle -> IOExcept Bool
hIsEOFOfHandle =
hIsEOF
hSetBufferingOfHandle :: Handle -> BufferMode -> IOExcept ()
hSetBufferingOfHandle =
hSetBuffering
exitWithOfCode :: ExitCode -> Maybe (IO ())
exitWithOfCode =
exitWith
-- Files, directories and threads: failures as values, and non-empty lists.
doesFileExistOfPath :: FilePath -> IOExcept Bool
doesFileExistOfPath =
doesFileExist
listDirectoryOfPath :: FilePath -> IOExcept [FilePath]
listDirectoryOfPath =
listDirectory
createDirectoryOfPath :: FilePath -> IOExcept ()
createDirectoryOfPath =
createDirectory
removeFileOfPath :: FilePath -> IOExcept ()
removeFileOfPath =
removeFile
copyFileOfPaths :: FilePath -> FilePath -> IOExcept ()
copyFileOfPaths =
copyFile
getCurrentDirectoryOfProcess :: IOExcept FilePath
getCurrentDirectoryOfProcess =
getCurrentDirectory
getTemporaryDirectoryOfProcess :: IOExcept FilePath
getTemporaryDirectoryOfProcess =
getTemporaryDirectory
withCurrentDirectoryOfPath :: FilePath -> IOExcept Text -> IOExcept Text
withCurrentDirectoryOfPath =
withCurrentDirectory
getSearchPathOfProcess :: IOExcept [FilePath]
getSearchPathOfProcess =
getSearchPath
waitExceptOfAsync :: Async Int -> ExceptT SomeException IO Int
waitExceptOfAsync =
waitExcept
waitAnyCatchOfNonEmpty :: NonEmpty (Async Int) -> IO (Async Int, Either SomeException Int)
waitAnyCatchOfNonEmpty =
waitAnyCatch
waitAnyCatchCancelOfNonEmpty :: NonEmpty (Async Int) -> IO (Async Int, Either SomeException Int)
waitAnyCatchCancelOfNonEmpty =
waitAnyCatchCancel
readMaybeOfText :: Text -> Maybe Int
readMaybeOfText =
readMaybe
readEitherOfText :: Text -> Either Text Int
readEitherOfText =
readEither
readIOOfText :: Text -> IO (Maybe Int)
readIOOfText =
readIO
dieOfText :: Text -> IO ()
dieOfText =
die