Skip to content

Conversation

abbashosseinii
Copy link

@abbashosseinii abbashosseinii commented Aug 31, 2025

This PR introduces the intersperse extension method to Iterable, which inserts a separator element between each element of the original sequence. This provides an efficient, lazy, and declarative way to achieve this common pattern.

For example, [1, 2, 3].intersperse(0) would produce an iterable yielding 1, 0, 2, 0, 3.

This addresses the feature request in issue #49900.

  • I've reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines

See our contributor guide for general expectations for PRs.

Larger or significant changes should be discussed in an issue before creating a PR.

Contributions to our repos should follow the Dart style guide and use dart format.

Most changes should add an entry to the changelog and may need to rev the pubspec package version.

Changes to packages require corresponding tests.

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@abbashosseinii abbashosseinii requested a review from a team as a code owner August 31, 2025 14:48
Copy link

google-cla bot commented Aug 31, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

…separation

Implement a new `intersperse` method that lazily inserts a specified separator between elements of an iterable. This method is memory-efficient and utilizes a generator for performance. Include comprehensive tests covering various scenarios, including empty iterables and different separator types.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant