Skip to content

Instantly share code, notes, and snippets.

@oisdk
Last active February 12, 2018 17:42
Show Gist options
  • Save oisdk/7002c6df30e4bce74b7835892ed47203 to your computer and use it in GitHub Desktop.
Save oisdk/7002c6df30e4bce74b7835892ed47203 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RecursiveDo #-}
import qualified Data.Map.Strict as Map
import Control.Monad.State.Strict
repMax :: (Traversable t, Ord a) => t a -> t a
repMax xs = flip evalState Nothing $ mdo
ys <- forM xs $ \x -> do
modify (max (Just x))
pure (max x res)
~(Just res) <- get
pure ys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment