From 8e92e6e11d2b3b0bfb5ac9d68f347219493e6380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 23 Sep 2020 17:44:40 +0200 Subject: split into library + executables --- src/Much/Utils.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/Much/Utils.hs (limited to 'src/Much/Utils.hs') diff --git a/src/Much/Utils.hs b/src/Much/Utils.hs new file mode 100644 index 0000000..80615fc --- /dev/null +++ b/src/Much/Utils.hs @@ -0,0 +1,28 @@ +module Much.Utils where + +import Control.Exception +import System.Directory +import System.IO + + +withTempFile :: FilePath -> String -> ((FilePath, Handle) -> IO a) -> IO a +withTempFile tmpdir template = + bracket (openTempFile tmpdir template) (removeFile . fst) + + +mintercalate :: Monoid b => b -> [b] -> b +mintercalate c (h:t) = foldl (\acc x -> acc <> c <> x) h t +mintercalate _ [] = mempty + + +padl :: Int -> a -> [a] -> [a] +padl n c s = + if length s < n + then padl n c (c:s) + else s + +padr :: Int -> a -> [a] -> [a] +padr n c s = + if length s < n + then padr n c (s ++ [c]) + else s -- cgit v1.2.3