Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sdk/lib/collection/collections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ part of dart.collection;
///
/// The source of the elements may be a [List] or any [Iterable] with
/// efficient [Iterable.length] and [Iterable.elementAt].
///
/// ```dart
/// final numbers = <int>[10, 20, 30];
/// final unmodifiableListView = UnmodifiableListView(numbers);
///
/// // Insert new elements into the original list.
/// numbers.addAll([40, 50]);
/// print(unmodifiableListView); // [10, 20, 30, 40, 50]
///
/// unmodifiableListView.remove(20); // Throws.
/// ```
class UnmodifiableListView<E> extends UnmodifiableListBase<E> {
final Iterable<E> _source;

Expand Down
13 changes: 12 additions & 1 deletion sdk/lib/collection/maps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ abstract class MapMixin<K, V> implements Map<K, V> {
/// Basic implementation of an unmodifiable [Map].
///
/// This class has a basic implementation of all but two of the members of
/// an umodifiable [Map].
/// an unmodifiable [Map].
/// A simple unmodifiable `Map` class can be implemented by extending this
/// class and implementing `keys` and `operator[]`.
///
Expand Down Expand Up @@ -376,6 +376,17 @@ class MapView<K, V> implements Map<K, V> {
/// A wrapper around a `Map` that forwards all members to the map provided in
/// the constructor, except for operations that modify the map.
/// Modifying operations throw instead.
///
/// ```dart
/// final baseMap = <int, String>{1: 'Mars', 2: 'Mercury', 3: 'Venus'};
/// final unmodifiableMapView = UnmodifiableMapView(baseMap);
///
/// // Remove an entry from the original map.
/// baseMap.remove(3);
/// print(unmodifiableMapView); // {1: Mars, 2: Mercury}
///
/// unmodifiableMapView.remove(1); // Throws.
/// ```
class UnmodifiableMapView<K, V> extends MapView<K, V>
with _UnmodifiableMapMixin<K, V> {
UnmodifiableMapView(Map<K, V> map) : super(map);
Expand Down
11 changes: 11 additions & 0 deletions sdk/lib/collection/set.dart
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@ class _UnmodifiableSet<E> extends _SetBase<E> with _UnmodifiableSetMixin<E> {
///
/// Methods that could change the set, such as [add] and [remove],
/// must not be called.
///
/// ```dart
/// final baseSet = <String>{'Mars', 'Mercury', 'Earth', 'Venus'};
/// final unmodifiableSetView = UnmodifiableSetView(baseSet);
///
/// // Remove an element from the original set.
/// baseSet.remove('Venus');
/// print(unmodifiableSetView); // {Mars, Mercury, Earth}
///
/// unmodifiableSetView.remove('Earth'); // Throws.
/// ```
@Since("2.12")
class UnmodifiableSetView<E> extends SetBase<E> with _UnmodifiableSetMixin<E> {
final Set<E> _source;
Expand Down