Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import Control.Arrow (loop)
replaceWithMax, replaceWithMax' :: Ord a => [a] -> [a]
replaceWithMax xs =
let (result, max) = go (xs, max)
in result
where
go ([], replacer) = ([], replacer)
go ([x], replacer) = ([replacer], x)
go ((x:xs), replacer) =
let (xs', replacer') = go (xs, replacer)
in (replacer : xs', max replacer' x)
replaceWithMax' = loop go
where
go ([], replacer) = ([], replacer)
go ([x], replacer) = ([replacer], x)
go ((x:xs), replacer) =
let (xs', replacer') = go (xs, replacer)
in (replacer : xs', max replacer' x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.