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

Add properties and methods to Mapping/Listing API to resemble Map/List more #672

Closed
wants to merge 18 commits into from

Conversation

holzensp
Copy link
Contributor

@holzensp holzensp commented Oct 9, 2024

No description provided.

Comment on lines +1968 to +1972
/// The values contained in this mapping.
external values: List<Value>

/// The entries contained in this mapping.
external entries: List<Pair<Key, Value>>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a particular reason why there are Lists while keys is a Set? Mappings are ordered (and documented as such), so this sort of makes sense to me. Having this reasoning documented might be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO these should be Listings, and keys should be changed to Listing via a deprecation cycle.

@StefMa
Copy link
Contributor

StefMa commented Oct 9, 2024

While we are here, what is the reason that pkl has Mappings and Map and Listing and List? 🤔

@bioball
Copy link
Contributor

bioball commented Oct 10, 2024

While we are here, what is the reason that pkl has Mappings and Map and Listing and List?

Several reasons (not comprehensive):

  • Mapping and Listing are values of type Object; their members are lazy and late-bound, which has implications around how the object is represented in the underlying implementation. Map and List are a lot more performant for "algorithm-y" type logic; e.g. concat, map, filter, etc.
  • Mapping and Listing have a special property called "default". It's not really clear how something like .map() and .flatMap() should work; what do you do with the special "default" property?

It'd be good to simplify the language and not have this dichotomy, but we'd need to at least solve the above challenges first.

var keys = getAllKeys();
var builder = new VmObjectBuilder(keys.getLength());
for (var key: keys) {
var member = VmUtils.readMember(this, key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of forcing and copying each value, the Dynamic could delegate to the Mapping via addEntry(Object key, SharedMemberNode valueNode).
A similar overload could be added for addProperty (I didn't need it at the time).

@holzensp
Copy link
Contributor Author

Closing this as an outdated duplicate of #683.

@holzensp holzensp closed this Oct 28, 2024
@holzensp holzensp deleted the mappingListingParity branch October 31, 2024 14:56
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.

5 participants