expectations 0.1.0

Paul Backus snarwin at gmail.com
Sun Sep 2 06:59:20 UTC 2018


expectations is an error-handling library that lets you bundle 
exceptions together with return values. It is based on Rust's 
Result<T, E> [1] and C++'s proposed std::expected. [2] If you're 
not familiar with those, Andrei's NDC Oslo talk, "Expect the 
Expected" [3], explains the advantages of this approach to error 
handling in considerable detail.

Features:
- `Expected` values can be treated as either return codes or 
exceptions.
- Functions that return `Expected` values can be composed easily 
using a monadic interface (`andThen`).
- `Expected!void` is valid and (hopefully) works the way you'd 
expect.
- Everything, except for `opEquals` (which depends on 
`Object.opEquals`), works in @safe code.

This is very much a work in progress; all comments and feedback 
are welcome.

Documentation: 
https://pbackus.github.io/expectations/expectations.html
DUB: https://code.dlang.org/packages/expectations
Code: https://github.com/pbackus/expectations

[1] https://doc.rust-lang.org/std/result/enum.Result.html
[2] https://wg21.link/p0323r7
[3] https://www.youtube.com/watch?v=nVzgkepAg5Y


More information about the Digitalmars-d-announce mailing list