Skip to content
pubscout

intersperse

2.0.0, released 6 years ago by modulovalue.com

Insert a given element between each element of an Iterable or List.

WASM-ready
$ flutter pub add intersperse
Source repository

What it does

The package provides a function that takes an iterable and a separator element and returns a new iterable where the separator is placed between every original element. It works with any Dart collection and supports null‑safety.

AI-written summary of version 2.0.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need to add separators (e.g., commas, dividers) when formatting output
  • You want a concise way to interleave items in a list without writing manual loops

Skip it when

  • Performance‑critical code with very large collections
  • When you need asynchronous or stream‑based interleaving

Strengths

  • Zero dependencies
  • Null‑safety support
  • Works with any Iterable
  • Very small API surface

Weaknesses

  • Only works with synchronous iterables
  • No built‑in support for streams or async generators

Setup

Kind
Pure Dart
Effort
Low
Code generation
No
Direct dependencies
0
final result = [1, 2, 3].intersperse(0); // result: [1, 0, 2, 0, 3]

Alternatives

Packages that do the same job and could replace intersperse.

  • country_code

    Provides ISO 3166-1 country codes in an enum-like class with parsing and user-assigned elements.

  • diffutil_dart

    Calculate the difference between two lists as a list of edit operations.

  • list_ext

    Dart extension methods for Iterable and List like sum, count, chunks, and sorting.

  • sorted_list

    A Dart list that automatically keeps its elements sorted.