aboutsummaryrefslogtreecommitdiff
path: root/challenge-001/alexander-pankoff/haskell/ch-1.hs
blob: f10946fade408075cd0c7886199bb0a9e09ea861 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Main where

import Data.Bifunctor (first)

main :: IO ()
main = print $ replaceAndCount 'e' 'E' "Perl Weekly Challenge"

replaceAndCount :: Char -> Char -> String -> (String, Int)
replaceAndCount taret replacement = first reverse . foldl go ("", 0)
  where
    go (replaced, count) cur =
      if cur == taret
        then (replacement : replaced, succ count)
        else (cur : replaced, count)