Created
December 4, 2018 22:42
-
-
Save bradparker/139a023de6c43771932bb94c5ded01ef to your computer and use it in GitHub Desktop.
Expanding int maps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ExpandMap | |
( expandIntMap | |
) where | |
import Control.Monad.State (evalState, get, put) | |
import Data.IntMap (IntMap) | |
import qualified Data.IntMap as IntMap | |
import Data.Traversable (for) | |
-- >>> expandIntMap '0' 50 (IntMap.fromList (zip [0,5..50] ['a' .. 'z'])) | |
-- "aaaaabbbbbcccccdddddeeeeefffffggggghhhhhiiiiijjjjjk" | |
expandIntMap :: a -> Int -> IntMap a -> [a] | |
expandIntMap a n m = | |
flip evalState a $ | |
for [0 .. n] $ \i -> | |
maybe (pure ()) put (IntMap.lookup i m) *> get |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment