google / built_collection.dart

Immutable Dart collections via the builder pattern.
https://pub.dev/packages/built_collection
BSD 3-Clause "New" or "Revised" License
275 stars 52 forks source link

Built Collections deep comparison question #277

Closed Region40 closed 1 year ago

Region40 commented 1 year ago

The documentation states:

Built Collections do a deep comparison against other Built Collections of the same type, only.

I took that to mean that a BuiltList can be deep compared only if the collections it contains are also BuiltLists.

Here's an example of what I understood to be true:

// ✔ can be deep compared; BuiltList contains BuiltLists
BuiltList<BuiltList<String>> builtList1 = . . .
BuiltList<BuiltList<String>> builtList2 = . . .

----------

// ❌ can NOT be deep compared; BuiltList contains BuiltSets — not same types
BuiltList<BuiltSet<String>> builtList1 = . . .
BuiltList<BuiltSet<String>> builtList2 = . . .

However, I tested this, and it seems like my understanding is incorrect:

test(
  'Test BuiltList equality',
  () {
    BuiltList<BuiltSet<String>> list1 = BuiltList<BuiltSet<String>>([BuiltSet<String>(["One"])]);
    BuiltList<BuiltSet<String>> list2 = BuiltList<BuiltSet<String>>([BuiltSet<String>(["One"])]);
    expect(list1, equals(list2)); // true
  },
);

After testing this, and considering the possible interpretations of the above documentation, I believe I misunderstood the documentation, initially. I was hoping to confirm this and get clarification over what scenario the documentation above is describing. If I can get clarification, I'd be happy to make a PR to the README with a code sample to illustrate the above documentation to help others avoid experiencing the same misinterpretation I did.

davidmorgan commented 1 year ago

Hmm, the docs say "other Built Collections of the same type", without referring to the contents of the collection.

So I think the docs are correct as far as they go.

Cases where the values in the collection are also collections don't introduce anything new; BuiltList<T> works the same for any T where comparison works.

Possibly the confusion is caused by the term "deep comparison". That means that elements are compared by calling the operator== method of each pair of elements; "deep" in the sense that it calls more code. Maybe elaborating that would help?

Thanks.

Region40 commented 1 year ago

@davidmorgan, I have a solution, for this issue, based on your feedback that I'd like to present, but I have yet to sign the Google Individual Contributor License Agreement.

Before I do, I am just curious—if someone makes a contribution to this project, does their full name and email (which are both required to be submitted to Google when signing the Google Individual Contributor License Agreement) end up in the public AUTHORS.md file (either automatically, or manually by someone else as part of a systematic process / policy)?

I don't mind submitting my full name and email to Google for their own private attribution records, but I would prefer to avoid having that information presented to the public without my control.

davidmorgan commented 1 year ago

I can answer that one :) nothing gets automatically added to AUTHORS.md, you would have to add yourself manually to appear there. Then, of course, you can choose exactly what you want to add.