sorted_list
1.0.0, released 6 years ago by patchme.app
A Dart list that automatically keeps its elements sorted.
What it does
SortedList extends DelegatingList and inserts items in their correct order based on a comparator. Retrieval is fast because the list is always sorted, but insert operations are slower due to reordering.
AI-written summary of version 1.0.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need a collection that is always sorted for fast reads
- The data set is relatively static with few insertions
- You want a drop‑in replacement for List without managing sorting yourself
Skip it when
- Frequent insertions or large batches where insert cost matters
- You need to insert at arbitrary positions
- You require advanced list features like slicing or custom indexing
Strengths
- Keeps items sorted automatically
- Simple List‑like API
- Null‑safe implementation
Weaknesses
- Insert operations are slower due to sorting
- Cannot insert at a specific index
- Limited to basic list functionality
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 1
import 'package:sorted_list/sorted_list.dart';
void main() {
var sortedList = SortedList<int>((a, b) => a.compareTo(b));
sortedList.addAll([5, 1, 3, 2]);
for (var i in sortedList) {
print(i); // 1,2,3,5
}
}Alternatives
Packages that do the same job and could replace sorted_list.
- country_code
Provides ISO 3166-1 country codes in an enum-like class with parsing and user-assigned elements.
77Compare - intersperse
Insert a given element between each element of an Iterable or List.
50Compare - list_ext
Dart extension methods for Iterable and List like sum, count, chunks, and sorting.
50Compare - pluto_filtered_list
A Dart List where filters can be applied and elements accessed or modified in that state.
44Compare