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 methods from List/Map to Listing/Mapping #683

Merged
merged 27 commits into from
Oct 31, 2024

Conversation

holzensp
Copy link
Contributor

Methods that "project out" of the type can be added to Listing and Mapping to avoid having to use toList()/toMap(). Methods that result in a Listing, resp. Mapping, are not included for performance and (lazy) semantics reasons, but methods like contains etc. can be defined straightforwardly.

pkl-core/src/main/java/org/pkl/core/runtime/VmMapping.java Outdated Show resolved Hide resolved
pkl-core/src/main/java/org/pkl/core/runtime/VmMapping.java Outdated Show resolved Hide resolved
stdlib/base.pkl Outdated Show resolved Hide resolved
pkl-core/src/main/java/org/pkl/core/runtime/VmList.java Outdated Show resolved Hide resolved
stdlib/base.pkl Show resolved Hide resolved
@stackoverflow
Copy link
Contributor

I'm missing any and every for Listing.

@@ -128,6 +134,47 @@ public Map<Object, Object> toMap() {
return properties;
}

public VmDynamic toDynamic() {
EconomicMap<Object, ObjectMember> members = EconomicMaps.create(this.members.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should use VmObjectBuilder

Copy link
Contributor

@bioball bioball left a comment

Choose a reason for hiding this comment

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

I have mostly nits, but also: I think we should punt these methods to another PR:

  • toDynamic
  • Mapping.entries
  • Mapping.values

Also, there's still many methods that's missing! Not blocking, but it would be good to have. Here's what I see that I think we can add:

  • indexOf
  • indexOfOrNull
  • lastIndexOf
  • lastIndexOfOrNull
  • find
  • findOrNull
  • findLast
  • findLastOrNull
  • findIndex
  • findIndexOrNull
  • findLastIndex
  • findLastIndexOrNull
  • count
  • foldBack
  • foldIndexed
  • reduce
  • min
  • minOrNull
  • minBy
  • minByOrNull
  • minWith
  • minWithOrNull
  • max
  • maxOrNull
  • maxBy
  • maxByOrNull
  • maxWith
  • maxWithOrNull
  • indexOf

pkl-core/src/main/java/org/pkl/core/runtime/VmMapping.java Outdated Show resolved Hide resolved
stdlib/base.pkl Show resolved Hide resolved
stdlib/base.pkl Outdated Show resolved Hide resolved
stdlib/base.pkl Outdated Show resolved Hide resolved
stdlib/base.pkl Outdated Show resolved Hide resolved
Copy link
Contributor

@bioball bioball left a comment

Choose a reason for hiding this comment

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

Some more suggestions, but otherwise LGTM

@bioball bioball dismissed stackoverflow’s stale review October 31, 2024 03:18

comments have been addressed; reviewer currently unavailable to re-review

@holzensp holzensp force-pushed the cleanMappingListingParity branch from c272732 to 1d2d51b Compare October 31, 2024 13:54
Co-authored-by: Daniel Chao <daniel.h.chao@gmail.com>
@holzensp holzensp merged commit a038279 into apple:main Oct 31, 2024
5 checks passed
@holzensp holzensp deleted the cleanMappingListingParity branch October 31, 2024 14:54
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.

4 participants