The isolate function available in both binary and cereal provides a very useful abstraction.
With isolate:
isolate (fromIntegral len) $ case cmd of
MCVersion -> MVersion <$> get
MCAddr -> MAddr <$> get
_ -> fail $ "get: command " ++ show cmd ++ " should not carry a payload"
Without isolate:
ensure (fromIntegral len) >>= \bs ->
let f = case cmd of
MCVersion -> MVersion <$> deserialize
MCAddr -> MAddr <$> deserialize
_ -> fail $ "get: command " ++ show cmd ++ " should not carry a payload"
either fail return (runGetS f bs)
Getting out of the monad to get right back into it feels clumsy.
The
isolate
function available in bothbinary
andcereal
provides a very useful abstraction.With
isolate
:Without
isolate
:Getting out of the monad to get right back into it feels clumsy.