liveBook · Manning

Array

As explained in Functional Programming in Scala, Second Edition

An array is an indexed, fixed-size sequence of elements stored in contiguous or logically contiguous positions.

An array stores elements at indexed positions. Recursive algorithms can traverse those positions explicitly, stopping when the next index would exceed the array’s length. section 2.7

Arrays support both functional traversal and controlled mutation:

  • A tail-recursive loop can compare neighboring elements, return false when the supplied ordering function fails, and otherwise continue to the next index. section 2.7
  • An STArray can allocate, read, write, and freeze an array while keeping every access inside an ST action. section 14.2.4 section 14.5
  • Generic array creation requires a ClassTag[A], and arrays can be initialized from a size and default value or constructed from a List. section 14.2.4

How Functional Programming in Scala, Second Edition covers it

How deep it goes
Explains recursive traversal and STArray primitives, stopping short of a complete quicksort implementation.
Examples
Demonstrates neighboring-element checks, fill from a Map, List conversion, and an in-place quicksort setting.
What it assumes
Assumes Scala functions, generics, and arrays while teaching scoped mutation through STArray operations.
What you can do after
Build it from scratch by implementing indexed traversals and composing allocation, reading, writing, filling, and freezing operations.
How it connects
Connects arrays to tail recursion, the ST monad, mutable state, ClassTag, and quicksort.

Also explained in

Compare how 40 books explain array →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in Scala, Second Edition. The section links point to the parts of the book it draws on.