Skip to content

Instantly share code, notes, and snippets.

@josephcsible
Created February 4, 2021 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephcsible/93fac91fba828c42536908ac7d2f0f40 to your computer and use it in GitHub Desktop.
Save josephcsible/93fac91fba828c42536908ac7d2f0f40 to your computer and use it in GitHub Desktop.
import Control.Monad.State
import Data.Traversable
{-
>>> uglyMap (,,) "abc"
[('a',0,"abc"),('b',1,"abc"),('c',2,"abc")]
-}
uglyMap :: Traversable t => (a -> Int -> t a -> b) -> t a -> t b
uglyMap f xs = flip evalState 0 $ for xs $ \x -> do
i <- get
modify (+ 1)
pure $ f x i xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment