Skip to content

Conversation

@confusedalex
Copy link
Contributor

This impelements a sealed [1] class which sort of acts as a union tag. This will give us exhaustive switching for every timestamp, like this:

    section.visit<OrgGenericTimestamp>((node) {
      switch (node) { // => error
          // The type 'OrgGenericTimestamp' is not exhaustively matched by
          // the switch cases since it doesn't match OrgTimeRangeTimestamp()'.

          // do something
          break;

        case OrgSimpleTimestamp():
          // do something
          break;
      }
      return true;
    });

Also, because the OrgGenericTimestamp extends OrgNode, we can access toMarkup() and other methods directly from the OrgGenericTimestamp.

[1] https://dart.dev/language/class-modifiers#sealed

@confusedalex confusedalex force-pushed the feat-generictimestamp branch from 02b090f to e6ca015 Compare May 30, 2025 21:40
@amake
Copy link
Owner

amake commented May 30, 2025

Thanks for this! I figured there was a good way to do this, but coming from Java I've always found Dart's soup of keywords in this area to be confusing. I suspect there are some other groups of OrgNodes that could use the same treatment.

I thought we might as well call the common interface OrgTimestamp. Let me know if that's OK with you.

@confusedalex
Copy link
Contributor Author

Defining a interface and consolidating common attributes sound good!

@amake amake merged commit 7be14ea into amake:master May 31, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants