On Wednesday, 22 August 2018 at 22:49:52 UTC, Paul Backus wrote:
On Wednesday, 22 August 2018 at 22:11:05 UTC, aliak wrote:
On Monday, 20 August 2018 at 19:52:53 UTC, jmh530 wrote:

It's interesting that both sumtype and optional have match templates. Maybe scope to combine these projects?

That'd be cool. Optional uses .match on a "some" or "none" range, while SumType uses it on a union. So ideas on how to go about it?

In theory, Optional(T) could be implemented as a wrapper around SumType!(T, None), which would let it reuse SumType's match method. I'm not sure if it'd be worth the effort to convert at this point, though.

THis is true. And might be interesting to try out actually. Can you access the types in a SumType via index?

I'm thinking because Optional behaves like a range, and I guess I'd define a SumType!(T, None), then a rough outline may be:

struct None {}
immutable none = None();

struct(T) {
  SumType(T, None) opt;
  T front() {
    return opt[0]; // what to do here?
  }
}

Or I guess I should maybe do it like this?:

return opt.match!(
  (T val) => val,
  (None) => T.init,
);




Reply via email to