This chapter covers the containers and text tools used in everyday TalkTalk programs: arrays, ranges, loops, strings, and dictionaries.

Arrays

[T] is a growable, copy-on-write array:

Common operations include get, push, pop, swap, and indexed access. get returns an optional; subscript syntax is the direct form.

[T; N] is an InlineArray whose static length is part of the type. Use it for fixed-size data and static value generic APIs.

Iteration

for uses Iterable and Iterator. Iterator adapters are lazy until collected:

A user type can participate by conforming to Iterator:

for x in consume values consumes the source. for x in mut values iterates with writeback.

Ranges

lower..<upper excludes the upper bound and lower..upper includes it:

Integer ranges conform to Iterable without allocating an array.

Unicode text

Strings are UTF-8, and their user-facing character operations use extended grapheme clusters:

Iterating a String or Substring produces Character values. Lower-level views are explicit:

  • .utf8() iterates encoded bytes
  • .scalars() iterates Unicode scalar values
  • ordinary iteration produces grapheme-cluster Character values

The text surface includes searching, splitting, trimming, replacement, Unicode classification, case conversion, normalization, and cursor/index APIs. Index types carry provenance so an index from unrelated text cannot silently address a different string.

String building and conversion

StringBuilder supports repeated construction without a chain of intermediate strings. String and Substring implement StringMethods; many operations therefore read naturally as methods on either owned text or a view.

Showable converts values for display through .show(), and print accepts any Showable value. From<Source> and Into<Target> describe general library conversions.

Dictionaries

The standard library's dict module provides a growable string-keyed Dict<Value>:

The standard library is still growing; consult the source modules for the complete current API.