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

refactor: prefer {List,Map}.of over {List,Map}.from #4333

Merged
merged 2 commits into from
Jan 13, 2025

Conversation

kszczek
Copy link
Contributor

@kszczek kszczek commented Jan 13, 2025

Status

READY

Breaking Changes

NO

Description

Update the docs and a few test snippets to use List.of and Map.of instead of List.from and Map.from. The of factories offer better type-safety by enforcing the collection types at compile-time.

Some instances of the from factories remain, as they are used for type promotion. To find such cases, run the regex: (List|Map).*[.]from. These cases align with Dart's documentation on Map.from:

Prefer using Map.of when possible, and only use Map.from to create a new map with more precise types than the original, and when it's known that all the keys and values have those more precise types.

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

Update the docs and a few test snippets to use `List.of` and `Map.of`
instead of `List.from` and `Map.from`. The `of` factories offer better
type-safety by enforcing the collection types at compile-time.

Some instances of the `from` factories remain, as they are used for type
promotion. To find such cases, run the regex: `(List|Map).*[.]from`.
These cases align with Dart's documentation on `Map.from`:

> Prefer using Map.of when possible, and only use Map.from to create
> a new map with more precise types than the original, and when it's
> known that all the keys and values have those more precise types.
@kszczek kszczek requested a review from felangel as a code owner January 13, 2025 09:00
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (635e675) to head (acf7846).
Report is 22 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #4333   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           32        32           
  Lines          806       806           
=========================================
  Hits           806       806           
Flag Coverage Δ
hydrated_bloc 100.00% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@felangel felangel left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the contribution! 💙

@felangel felangel added the refactor Refactor an existing implementation label Jan 13, 2025
@felangel felangel enabled auto-merge (squash) January 13, 2025 17:51
@felangel felangel disabled auto-merge January 13, 2025 17:53
@felangel felangel merged commit 14db8f3 into felangel:master Jan 13, 2025
@kszczek kszczek deleted the prefer-of-over-from branch January 13, 2025 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Refactor an existing implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants