Skip to content

DART 3 Records Feature Requirement: Can it provide introspection capabilities similar to enum.values #2826

Closed
@chen56

Description

@chen56
const tree=(
  a:"/a",
  b:"/b",
    c:(
        a:"/c/a",
        b:"/c/b",
    ),
);

make records work same as a Map?

print(tree.keys);// [a,b,c]
print(tree["a"]);// "/a"

or may be like a array?

print(tree.length);// 3
print(tree.$1);// /a
print(tree[0]);// /a

I Read #2673 , but,I don't know how enum.values do it. Can it be implemented similarly?

This is very useful for implementing static variable trees,
now dart is very inconvenient,like this:

N<void> root = N<void>("/", meta: rootPage, kids: [
  N<void>("not_found", meta: notFoundPage),
  N<void>("note", meta: notePage, kids: [
    N<void>("material", kids: [
    ]),
  ]),
]);

N page(path) => root.kid(path);

class Paths {
  final N<void> home = page("/");
  final N<void> notFound = page("/not_found");
  final N<void> note = page("/note");
  final N<void> note_material = page("/note/material");

  Paths._();
}

var paths = Paths._();

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureProposed language feature that solves one or more problemsstate-rejectedThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions