dart-lang / collection

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.
https://pub.dev/packages/collection
BSD 3-Clause "New" or "Revised" License
372 stars 86 forks source link

Add flattenedToList and flattenedToSet #328

Closed natebosch closed 3 months ago

natebosch commented 8 months ago

For iterables which are known to be exhausted after flattening performance is better than the sync* implementation using a collection literal.

Add flattenedToList as a performance improvement over flattened. Add flattenedToSet as new behavior for flattening to unique elements.

Originally implemented in https://github.com/dart-lang/sdk/commit/8d3b6ce54ccb09dd970cd45fc3cded4a35beac31

natebosch commented 8 months ago

cc @scheglov - any concerns about landing this here? You might need to handle import conflicts when this version gets pulled in to the SDK.

natebosch commented 8 months ago

I'm not sure if we want to hold this on https://github.com/dart-lang/collection/pull/284 - we also have another new API on that branch waiting for publish.

lrhn commented 8 months ago

If someone needs this, it's fine to release it in 2.X, and merge it into the 3.0 branch too. Otherwise it's probably easier to just put it into the next major release.

I really should get back to releasing the 3.0 version.

scheglov commented 8 months ago

cc @scheglov - any concerns about landing this here? You might need to handle import conflicts when this version gets pulled in to the SDK.

https://dart-review.googlesource.com/c/sdk/+/346163 renames these methods in the analyzer, so there will be no conflict. I will migrate once this PR lands, and package:collection is pulled into SDK.

kevmoo commented 3 months ago

@natebosch – care to proceed?