Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collections in mixed #1383

Closed
wants to merge 1 commit into from
Closed

Collections in mixed #1383

wants to merge 1 commit into from

Conversation

nielsenko
Copy link
Contributor

@nielsenko nielsenko commented Aug 18, 2023

Allow RealmValues (mixed) to contain collections, and support a convenient syntax for constructing RealmValues of nested collections, and drilling into these to extract values.

Here is the suggested interface:

  final any = RealmValue.from([
    1,
    2,
    {
      'x': {1, 2}
    },
  ]);

  // access list element at index 2,
  // then map element with key 'x',
  // then set element 1, if it exists
  // assuming an int, or null if not found
  final x = any[2]['x'][1].as<int?>();
  assert(x == 1);

  // or, a bit shorter
  final y = any[2]['x'][1]<int?>();
  assert(y == 1);

  // or, shorter yet
  int? z = any[2]['x'][1]();
  assert(z == 1);

  // or, if you are sure
  int w = any[2]['x'][1](); // <-- shortest
  assert(w == 1);

  // or, using a list of indexes
  int u = any[[2, 'x', 1]]();
  assert(u == 1);

  // which allows for a different layout
  int v = any[[
    2,
    'x',
    1,
  ]]();
  assert(v == 1);

The code-behind is not done yet

@@ -227,3 +292,47 @@ class RealmValue {
@override
String toString() => 'RealmValue($value)';
}

void demo() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very early draft. Obviously this demo method should not survive

@nirinchev nirinchev closed this Feb 23, 2024
@nirinchev nirinchev deleted the kn/collections-in-mixed branch February 23, 2024 13:34
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants