Skip to content

Instantly share code, notes, and snippets.

@cloudhead
Last active July 28, 2016 00:14
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 cloudhead/fe0055549ccfa2c3e1d81045f78860ce to your computer and use it in GitHub Desktop.
Save cloudhead/fe0055549ccfa2c3e1d81045f78860ce to your computer and use it in GitHub Desktop.
newtype Inventory = Inventory (IntMap (Maybe Item))
nextFreeSlot :: Inventory -> Maybe IntMap.Key
nextFreeSlot (Inventory inv) =
go $ IntMap.toAscList inv
where
go ((k, Nothing) : _) = Just k
go [] = Nothing
go (_ : xs) = go xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment