On Tuesday, 29 April 2014 at 11:52:04 UTC, bearophile wrote:
Instead of the ugly and bug-prone mess of "read(fd, &size, sizeof(int));" I have used something nicer. "tryRead!uint" tries to read an uint, and returns a Nullable!uint. The "Maybe" is a function currently missing in Phobos (https://issues.dlang.org/show_bug.cgi?id=12679 ), it's used to chain other functions on nullables, so bswap gets called only if tryRead doesn't return a null value. If tryRead returns a null, then Maybe returns a nulled Nullable (currently I think "tryRead" is not present in Phobos, but it's not hard to add something similar, using parse).
Hopefully we will eventually get a good Option range type in Phobos, and use it everywhere that is applicable. Even though I don't like Nullable that much, I wish it or an Option type were used wherever they could be throughout Phobos. This would make a lot of code a lot more safe... We're already partway there with ranges, which are almost monads.
