First Draft: Callback For Matching Type
Richard Andrew Cattermole (Rikki)
richard at cattermole.co.nz
Sat Jun 22 21:02:34 UTC 2024
This proposal is a subset of matching capabilities to allow for
tagged unions to safely access with language support its values
and handle each tag.
Some minor things have been changed from the ideas thread, I have
changed the match block to be a declaration block to allow for
``static foreach`` and other conditional compilation language
features. So it is now using semicolon instead of colon.
```d
alias MTU = MyTaggedUnion!(int, float, string);
MTU mtu = MTU(1.5);
mtu.match {
(float v) => writeln("a float! ", v);
v => writeln("catch all! ", v);
};
```
Ideas thread:
https://forum.dlang.org/post/chzxzjiwsxmvnkthbdyy@forum.dlang.org
Latest:
https://gist.github.com/rikkimax/79cbe199618b3f99104f7df2fc2a9681
Permanent:
https://gist.github.com/rikkimax/79cbe199618b3f99104f7df2fc2a9681/95ae646da1ebb079a522b0c993e3408e5a1c0d78
More information about the dip.development
mailing list