Import std.collections.view
std.collections.view
Views of arrays, maps, and sets, which show them without copying.
Views that don't copy what they show: part of an array, which reads and sets it in place, and an array, Map, or Set to read but not change, to hand out. Each keeps what it shows alive and sees its changes. A slice, items[a..b], is still a copy.
Examples
Local numbers = [1, 2, 3, 4]
Expect(numbers.View(1, 3).ToArray() == [2, 3])
Local ages = {"Ada": 36}
Local shown = ages.AsReadOnly()
ages["Alan"] = 41
Expect(shown.Count == 2 && shown.Get("Alan") == 41)
Local seen = Set<Int>()
seen.Add(1)
Expect(seen.AsReadOnly().Contains(1))std/collections/view.fb
Types
ArrayView
class
@DebugElements Public Class ArrayView<T> Implements Iterable<T>
Part of an array, whose elements it reads and sets in place, counting from its own start. Its Count is the part's own, which stays as the array changes, and an element the array no longer has panics.
std/collections/view.fb, line 78
-
How many elements it shows.
-
The element at index, from 0 to Count minus 1.
-
Gives the element at index, from 0 to Count minus 1, a new value, in the array.
-
Part of this view, from
startup tofinish, without the one atfinish. -
The elements, in a new array.
-
The elements, in order.
ArrayViewIterator
struct
Public Struct ArrayViewIterator<T> Implements Iterator<T>
The elements of an ArrayView, in order, which a For loop goes over.
std/collections/view.fb, line 148
-
The next element, in order, or Null after the last.
ReadOnlyArray
class
@DebugElements Public Class ReadOnlyArray<T> Implements Iterable<T>
An array to read but not change, which AsReadOnly gives.
std/collections/view.fb, line 162
-
How many elements it holds.
-
The value at
index, which panics outside it. -
Whether it holds
value. -
The elements, in a new array, which can change.
-
The array's elements, in order.
ReadOnlyMap
class
@DebugEntries Public Class ReadOnlyMap<K: Hashable, V> Implements Iterable<(K, V)>
A Map to read but not change, which AsReadOnly gives.
std/collections/view.fb, line 193
-
How many entries it holds.
-
The key's value, or the Map's default when it isn't there, or a panic when it has none.
-
The value of
key, or Null when it has none. -
The value of
key, orfallbackwhen it has none. -
Whether
keyhas an entry. -
Its keys, in order, in a new array.
-
Its values, in order, in a new array.
-
The entries, in a new Map, which can change.
-
The Map's entries, in order.
ReadOnlySet
class
@DebugElements Public Class ReadOnlySet<T: Hashable> Implements Iterable<T>
A Set to read but not change, which AsReadOnly gives.
std/collections/view.fb, line 233
-
How many values it holds.
-
Whether it holds
value. -
The values, in a new array.
-
The values, in a new Set, which can change.
-
The Set's values, in order.
Extends
T[]
extend
Extend T[]
Views of every array: part of it, read and set in place, and the whole, to read but not change.
std/collections/view.fb, line 27
-
The elements from
startup tofinish, without the one atfinish, as a view of them in the array. They have to be in the array.Examples
Local numbers = [1, 2, 3, 4, 5] Local middle = numbers.View(1, 4) middle[0] = 20 Expect(numbers == [1, 20, 3, 4, 5]) Expect(middle.Count == 3 && middle.ToArray() == [20, 3, 4]) -
The array, to read but not change.
Examples
Local scores = [1, 2, 3] Local shown = scores.AsReadOnly() scores.Add(4) Expect(shown.Count == 4 && shown[3] == 4)
Map
extend
Extend Map<K, V>
A view of every Map, to read but not change.
std/collections/view.fb, line 64
-
The Map, to read but not change.
Set
extend
Extend Set<T>
A view of every Set, to read but not change.
std/collections/view.fb, line 70
-
The Set, to read but not change.
ArrayView
extend
Extend ArrayView<T> Implements Printable
Shows an ArrayView in a string, as its ToString writes it.
std/collections/view.fb, line 261
-
The elements it shows, as an array shows them: "[1, 2, 3]".
ReadOnlyArray
extend
Extend ReadOnlyArray<T> Implements Printable
Shows a ReadOnlyArray in a string, as its ToString writes it.
std/collections/view.fb, line 270
-
The array, as it shows itself: "[1, 2, 3]".
ReadOnlyMap
extend
Extend ReadOnlyMap<K, V> Implements Printable
Shows a ReadOnlyMap in a string, as its ToString writes it.
std/collections/view.fb, line 278
-
The Map, as it shows itself: "{a: 1, b: 2}".
ReadOnlySet
extend
Extend ReadOnlySet<T> Implements Printable
Shows a ReadOnlySet in a string, as its ToString writes it.
std/collections/view.fb, line 287
-
The Set, as it shows itself: "{1, 2, 3}".
Report an issue with this page or with FutureBlitz on GitHub.