-- | Add a handler to a handler map.
addHandler :: Handler a -> HandlerMap a -> (HandlerRef,HandlerMap a)
addHandler k hs = (ref, hs')
  where
  ref = handlerNextId hs
  hs' = HandlerMap
    { handlers      = Map.insert (handlerNextId hs) k (handlers hs)
    , handlerNextId = handlerNextId hs + 1
    }

-- | Remove a handler from a handler map.
addHandler :: Handler a -> HandlerMap a -> (HandlerRef,HandlerMap a)
addHandler k hs = (ref, hs')
  where
  ref = handlerNextId hs
  hs' = HandlerMap
    { handlers      = Map.insert (handlerNextId hs) k (handlers hs)
    , handlerNextId = handlerNextId hs + 1
    }

-- | Remove a handler from a handler map.
addHandler k hs = (ref, hs')
  where
  ref = handlerNextId hs
  hs' = HandlerMap
    { handlers      = Map.insert (handlerNextId hs) k (handlers hs)
    , handlerNextId = handlerNextId hs + 1
    }

-- | Remove a handler from a handler map.