-
Notifications
You must be signed in to change notification settings - Fork 13
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels