Skip to main content
Version: Next

Collections

FScript has lists, tuples, options, records, maps, and unions.

Lists

let numbers = [1; 2; 3]
let doubled = numbers |> List.map (fun n -> n * 2)

Tuples

let pair = ("api", 3)

Options

let maybeName = Some "Ada"
let name = maybeName |> Option.defaultValue "unknown"

Records

type Person = { Name: string; Age: int }
let p = { Name = "Ada"; Age = 37 }
let older = { p with Age = 38 }

Maps

let scores = { ["math"] = 18; ["science"] = 20 }
let maybeMath = scores |> Map.tryGet "math"

Maps always use a string indexer key type.

  • Valid map indexing/key usage uses strings: scores |> Map.tryGet "math".
  • Invalid key types (like int, bool) are not allowed.
// Invalid: numeric key type
// let invalid = { [1] = "one" }