What is the 'Result' type even for?
Ruby The Roobster
rubytheroobster at yandex.com
Fri Jan 20 03:11:33 UTC 2023
Take this example:
```d
import std;
void main()
{
auto c = "a|b|c|d|e".splitter('|');
c.writeln;
string[] e = ["a", "b", "c", "d", "e"];
assert(c.equal(e));
typeof(c).stringof.writeln;
}
```
The program prints:
["a", "b", "c", "d", "e"]
Result
What is the purpose of this 'Result' type? To serve as a generic
range? Because, it seems to only cause problems. For example,
you cannot assign or cast the result type into a range, even when
the type has the same inherent function:
```d
string[] c = "a|b|c|d|e".splitter('|'); // fails
string[] d = cast(string[])"a|b|c|d|e".splitter('|'); // also
fails
```
And if you need to perform a set operation?
```d
c[] ~= "lolno"; // fails, as [] isn't defined for Result.
```
Then what is the point of this type, if not to just make things
difficult? It cannot be casted, and vector operations cannot be
performed, and it seems to just serve as an unnecessary
generalization.
More information about the Digitalmars-d-learn
mailing list