Skip to content

Instantly share code, notes, and snippets.

@lumie1337
Created October 23, 2019 02:54
Show Gist options
  • Save lumie1337/06ae42e03bdc9567911a692964c2ea6c to your computer and use it in GitHub Desktop.
Save lumie1337/06ae42e03bdc9567911a692964c2ea6c to your computer and use it in GitHub Desktop.
addName counter names name = do
i <- readTVar counter
ns <- readTVar names
orElse addName' $ return ()
where
addName' = do
guard $ any ((== name) . snd) ns
writeTVar names ((i, name) : ns)
writeTVar counter (i + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment