diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2021-12-07 12:43:51 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2021-12-07 14:18:09 +0200 |
| commit | 3142bbcc613f880a9356ac1c837e2902f12a168e (patch) | |
| tree | 45859d8b08c09a1b90eb986ff8f388eb32d1693d /utils.hs | |
| parent | 38e975a00a4b4739bf3b818fd8632578660fa05b (diff) | |
Day 04
Diffstat (limited to 'utils.hs')
| -rw-r--r-- | utils.hs | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -1,7 +1,25 @@ module Utils where +import Control.Applicative (ZipList (ZipList, getZipList)) + (.>) = flip (.) ($>) = flip ($) infixr 6 $> + +splitOn :: (Char -> Bool) -> String -> [String] +splitOn p s = case dropWhile p s of + "" -> [] + s' -> w : splitOn p s'' + where + (w, s'') = break p s' + +transpose :: [[a]] -> [[a]] +transpose = getZipList . traverse ZipList + +mapWithIndex :: (Num a1, Enum a1) => (a2 -> b) -> [a2] -> [(a1, b)] +mapWithIndex f xs = zip [0 ..] (map f xs) + +removeAt :: [Int] -> [b] -> [b] +removeAt is xs = mapWithIndex id xs $> filter (\(i', _) -> i' `notElem` is) .> map snd |
