Sha256: 83921bf773bb17d7ab1b64ae311f4b9afd295cf28f2788834c9e7f95f7acb3fa
Contents?: true
Size: 621 Bytes
Versions: 374
Compression:
Stored size: 621 Bytes
Contents
module Robot (Robot, mkRobot, robotName, resetName) where import Control.Concurrent (MVar, readMVar, swapMVar, newMVar) import Control.Monad (void) import System.Random (randomRIO) newtype Robot = Robot { robotNameVar :: MVar String } mkRobot :: IO Robot mkRobot = fmap Robot $ generateName >>= newMVar resetName :: Robot -> IO () resetName r = void (generateName >>= swapMVar (robotNameVar r)) robotName :: Robot -> IO String robotName = readMVar . robotNameVar generateName :: IO String generateName = mapM randomRIO [ letter, letter, digit, digit, digit ] where letter = ('A', 'Z') digit = ('0', '9')
Version data entries
374 entries across 374 versions & 1 rubygems