Writing pattern matching macros in D.

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 6 12:25:51 PST 2017


On 2017-03-06 17:27, Deech wrote:

> I was thinking something on the order of Scala's pattern matching using
> apply/unapply methods. http://www.artima.com/pins1ed/extractors.html.

That should be possible. Although not as a macro and not with the same 
nice syntax. Something like this should be possible:

1.match(
     3, e => writeln("value is 3"),
     (int e) => writeln("value is an integer"),
     () => writeln("fallback")
);

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list