Skip to content

Records: expose named/optional fields through an extension getter instead of a static method #1275

Closed
@jakemac53

Description

@jakemac53

This was probably considered, but it might be nice to expose these static methods:

abstract class Record {
  static Iterable<Object?> positionalFields(Record record);
  static Map<Symbol, Object?> namedFields(Record record);
}

Instead as an extension on the Record class:

extension RecordInfo on Record {
  external Iterable<Object?> get positionalFields;
  external Map<Symbol, Object?> get namedFields;
}

This would be easier use, myRecord.positionalFields vs Record.positionalFields(myRecord), and it would prevent grabbing a tearoff of these methods.

One bonus of preventing a tearoff is that the compilers should be able to easily know exactly where and how these getters are invoked (and on what record types), and potentially optimize/treeshake better with that knowledge.

Metadata

Metadata

Assignees

No one assigned

    Labels

    patternsIssues related to pattern matching.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions