Pattern matching

Two Fer
Two Fer στη διαδρομή F#
module TwoFer

let twoFer (nameOpt: string option): string =
    let name =
        match nameOpt with
        | Some name -> name
        | None -> "you"

    $"One for {name}, one for me."

We use pattern matching to get the name we need to use in our greeting:

  1. Some name matches when a name was specified. In this case, we'll just return that name
  2. None matching when no name was specified. We'll return "you" in this case

We then use string interpolation to build the return string where {name} is replaced with the name we just found.

String formatting

The string formatting article discusses alternative ways to format the returned string.

14 Οκτώβριος 2026 · Σου φάνηκε χρήσιμη;

Άλλες προσεγγίσεις για την άσκηση Two Fer στη διαδρομή F#

Άλλοι τρόποι με τους οποίους η κοινότητά μας έλυσε αυτή την άσκηση