From 7800c56459c3e919c7d222201afd06d88f26d16a Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Thu, 8 Dec 2022 13:34:18 +0100 Subject: Day 4: Improve recursion is splitAtCharacter --- Day4/app/Main.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Day4/app/Main.hs b/Day4/app/Main.hs index 62a9817..bf1bd11 100644 --- a/Day4/app/Main.hs +++ b/Day4/app/Main.hs @@ -1,7 +1,7 @@ module Main (main) where -import System.Environment -import qualified Data.Bifunctor +import System.Environment ( getArgs ) +import Data.Bifunctor ( Bifunctor(bimap, first) ) main :: IO () main = getArgs >>= readFile . head >>= print . solveDay4 @@ -21,7 +21,7 @@ splitAtChar :: Char -> String -> (String, String) splitAtChar c x = splitAtCharacter c ("",x) splitAtCharacter :: Char -> (String, String) -> (String, String) -splitAtCharacter c (a, b:bs) = if b == c then (a,bs) else splitAtCharacter c (a++[b], bs) +splitAtCharacter c (a, b:bs) = if b == c then (a,bs) else Data.Bifunctor.first (b:) (splitAtCharacter c (a, bs)) splitAtCharacter c (a,[]) = (a,[]) parseRange :: String -> CleaningCells -- cgit v1.2.3