ekmett / ekmett/bytes

I miss isolate

Open
#55 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
23
Forks
13
PR merge metrics
No merged PRs in 30d

Description

The `isolate` function available in both `binary` and `cereal` provides a very useful abstraction.

With `isolate`:
```haskell
isolate (fromIntegral len) $ case cmd of
MCVersion -> MVersion <$> get
MCAddr -> MAddr <$> get
_ -> fail $ "get: command " ++ show cmd ++ " should not carry a payload"
```

Without `isolate`:
```haskell
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.