liveBook · Manning

Tuple deconstruction

As explained in F# in Action: A Revised Edition of Get Programming with F#

Tuple deconstruction is the extraction of a tuple's elements into separate bindings or pattern components.

Tuple deconstruction binds a tuple’s elements to separate names or pattern components in one step. It removes positional-access boilerplate and makes the values a function uses explicit. section 5.2.2

Use deconstruction to:

  • Discard unwanted elements with `_`, documenting that they are intentionally unused. section 5.2.2

Extract only the values you need

let nameAndAge = "Jane", "Smith", 25 let forename, surname, _ = nameAndAge let makeDoctor (_, surname) = "Dr", surname The first pattern ignores age; the second ignores the forename and returns a title with the surname.

How F# in Action: A Revised Edition of Get Programming with F# covers it

How deep it goes
Explains wildcards, nested patterns, inference, annotations, and struct tuples through compact examples.
Examples
Uses name-and-age tuples, nested tuples, surname extraction, and DateTime.TryParse result binding.
What it assumes
Assumes familiarity with tuple construction and bindings while showing tuple structure and inferred types through examples.
What you can do after
Apply it via F# pattern bindings and function parameters to name, discard, or reshape tuple elements.
How it connects
Connects tuple deconstruction with tuples, wildcard patterns, type inference, type annotations, and struct tuples.

This explainer was generated by Manning's knowledge graph from the text of F# in Action: A Revised Edition of Get Programming with F#. The section links point to the parts of the book it draws on.