Sha256: b057bf24efb024728e795c19355efe55f020e30aa7732daa5530695555012a38
Contents?: true
Size: 618 Bytes
Versions: 22
Compression:
Stored size: 618 Bytes
Contents
module Robot (Robot, mkRobot, robotName, resetName) where import Control.Concurrent (MVar, readMVar, swapMVar, newMVar) import Control.Monad (void) import System.Random (randomRIO) data 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
22 entries across 22 versions & 1 rubygems