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 whereType extension methods for iterables of union extension types. #71

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

davidmorgan
Copy link
Contributor

It occurred to me that this might be a useful type of extension method to add, what do you think?

@@ -514,6 +514,33 @@ extension type StaticTypeDesc.fromJson(Map<String, Object?> node)
}
}

extension IterableOfStaticTypeDescExtension on Iterable<StaticTypeDesc> {
Iterable<DynamicTypeDesc> whereTypeDynamicTypeDesc() =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry a bit about exposing these Iterables, especially with the likely high cost of iteration (and map lookups involved) due to the underlying representation here, combined with the lack of composability of them.

I also don't love the naming scheme haha. Maybe just remove the first Type? So, whereDynamicTypeDesc, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Iteration like this is likely to be common if we have e.g. a Map<String, Member> and you want to iterate over all the members that are Field.

That iteration is actually fast :) the iterable keeps a pointer into the JsonBufferBuilder and just advances to next each time.

Re: naming, yeah, I did think about getting rid of Type, then I realized that if we have a type called Type then you end up with whereType which clashes horribly. So I backed off a bit ;)

Mostly I just sent this because the examples I was writing for the "dart model evolution" doc looked quite ugly without it, no particular urgency to landing it; these are easy to add and should probably be driven by the macro code.

So let's land some macro code first? :)

@davidmorgan davidmorgan mentioned this pull request Oct 2, 2024
@davidmorgan davidmorgan marked this pull request as draft November 12, 2024 19:52
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.

2 participants