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

Make .flatten() type-safe #56

Merged
merged 3 commits into from
Mar 3, 2020
Merged

Make .flatten() type-safe #56

merged 3 commits into from
Mar 3, 2020

Conversation

passsy
Copy link
Collaborator

@passsy passsy commented Feb 5, 2020

Removes Iterable<E>.flatten(): Iterable<dynamic> in favor of

  • Iterable<Itearble<E>>.flatten(): Iterable<E> and
  • List<List<E>>.flatten(): List<E>

The old implementation wasn't type safe and risks a class cast exception

  Iterable<dynamic> flatten() sync* {
    for (var current in this) {
      yield* (current as Iterable); // cast may fail
    }
  }

I consider this change as almost-non-breaking 😁
If flatten() was called on a non-nested Iterable<E> where E is not a Iterable it would fail at runtime. So the code was already broken.
The only exception is when Iterable<dynamic> is empty. For this code the method will not be available anymore.

This PR is a alternative to #55

@shinayser
Copy link
Contributor

DO IT!

@passsy passsy requested a review from simc February 5, 2020 23:28
Copy link
Owner

@simc simc left a comment

Choose a reason for hiding this comment

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

👍

@passsy passsy merged commit 8b26178 into master Mar 3, 2020
@passsy passsy deleted the feature/type_safe_flatten branch March 3, 2020 15:55
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.

3 participants