Skip to content
FutureBlitz

    Install

    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

    • Public Property Count: Int property #

      How many elements it shows.

    • @PanicsAtCaller Operator [](index: Int): T operator #

      The element at index, from 0 to Count minus 1.

    • @PanicsAtCaller Operator []=(index: Int, value: T) operator #

      Gives the element at index, from 0 to Count minus 1, a new value, in the array.

    • @PanicsAtCaller Public Method View(start: Int, finish: Int): ArrayView<T> method #

      Part of this view, from start up to finish, without the one at finish.

    • @PanicsAtCaller Public Method ToArray(): T[] method #

      The elements, in a new array.

    • Public Method Iterate(): ArrayViewIterator<T> method #

      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

    • @PanicsAtCaller Public ByRef Method Next(): T? method #

      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

    • Public Property Count: Int property #

      How many elements it holds.

    • @PanicsAtCaller Operator [](index: Int): T operator #

      The value at index, which panics outside it.

    • Public Method Contains(value: T): Bool method #

      Whether it holds value.

    • Public Method ToArray(): T[] method #

      The elements, in a new array, which can change.

    • Public Method Iterate(): ArrayIterator<T> method #

      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

    • Public Property Count: Int property #

      How many entries it holds.

    • @PanicsAtCaller Operator [](key: K): V operator #

      The key's value, or the Map's default when it isn't there, or a panic when it has none.

    • Public Method Get(key: K): V? method #

      The value of key, or Null when it has none.

    • Public Method Get(key: K, fallback: V): V method #

      The value of key, or fallback when it has none.

    • Public Method Contains(key: K): Bool method #

      Whether key has an entry.

    • Public Method Keys(): K[] method #

      Its keys, in order, in a new array.

    • Public Method Values(): V[] method #

      Its values, in order, in a new array.

    • Public Method ToMap(): Map<K, V> method #

      The entries, in a new Map, which can change.

    • Public Method Iterate(): MapIterator<K, V> method #

      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

    • Public Property Count: Int property #

      How many values it holds.

    • Public Method Contains(value: T): Bool method #

      Whether it holds value.

    • Public Method ToArray(): T[] method #

      The values, in a new array.

    • Public Method ToSet(): Set<T> method #

      The values, in a new Set, which can change.

    • Public Method Iterate(): SetIterator<T> method #

      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

    • @PanicsAtCaller Public Method View(start: Int, finish: Int): ArrayView<T> method #

      The elements from start up to finish, without the one at finish, 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])
    • Public Method AsReadOnly(): ReadOnlyArray<T> method #

      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

    • Public Method AsReadOnly(): ReadOnlyMap<K, V> method #

      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

    • Public Method AsReadOnly(): ReadOnlySet<T> method #

      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

    • @PanicsAtCaller Public Method ToString(): String method #

      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

    • Public Method ToString(): String method #

      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

    • Public Method ToString(): String method #

      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

    • Public Method ToString(): String method #

      The Set, as it shows itself: "{1, 2, 3}".

    Report an issue with this page or with FutureBlitz on GitHub.