digitalmars.D.learn - Result and Option types
- powerboat9 (1/1) Jul 25 2020 Does dlang have an analog to Result or Option types from rust?
- FreeSlave (7/8) Jul 25 2020 Standard library has std.typecons.Nullable
- Paul Backus (10/11) Jul 25 2020 In addition to Nullable in the standard library, there are some
Does dlang have an analog to Result or Option types from rust?
Jul 25 2020
On Saturday, 25 July 2020 at 18:06:51 UTC, powerboat9 wrote:Does dlang have an analog to Result or Option types from rust?Standard library has std.typecons.Nullable https://dlang.org/phobos/std_typecons.html#Nullable Note that objects are nullable by themselves as classes are reference types. As for Result it's easy to implement using Tuple and writing some additional functions.
Jul 25 2020
On Saturday, 25 July 2020 at 18:06:51 UTC, powerboat9 wrote:Does dlang have an analog to Result or Option types from rust?In addition to Nullable in the standard library, there are some packages on dub you might find useful: * optional: an option type that can also function as a range, for compatibility with std.algorithm. Link: https://code.dlang.org/packages/optional * expected: a result type with customizable error behavior (can panic or throw on failed unwrap) and utility functions for monadic error handling (map, andThen, orElse). Link: https://code.dlang.org/packages/expected
Jul 25 2020