Lesson 9. Shaping data with tuples

You’ll start this unit by looking at the simplest data structure in F#, the tuple. Tuples are a great way to quickly pass small bits of data around your code when classes or similar elements feel like overkill. In this lesson

  • You’ll see how tuples are used within F#.
  • You’ll understand when to use and not use them.
  • You’ll see how tuples work together with type inference to enable succinct code.
  • You’ll see how tuples relate to the rest of .NET.

9.1. The need for tuples

Let’s start by considering an example that seems trivial and yet gets us in all sorts of contortions nearly every day. The following method takes in a string that contains an individual’s name (for example, "Isaac Abraham") and splits it into ...

Get Get Programming with F# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.