Skip to content

I miss isolate #55

@jprupp

Description

@jprupp

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions