Saturday, June 3, 2017

F# Functions

In Visual Studio Code enter the following code then, to run it, highlight it and press Option Enter:
let helloWorld = 
    "Hello from FSI"

printfn "%s" helloWorld
and get this result:
Hello from FSI
In Visual Studio Code enter the following code then, to run it, highlight it and press Option Enter:
let prefix preStr postStr = 
  preStr + ", " + postStr

prefix "Hello" "Greg"
and get this result:
val it : string = "Hello, Greg"
In Visual Studio Code enter the following code then, to run it, highlight it and press Option Enter:
let names = ["Joe"; "Sue"; "Mary"; "Bill"]

names
|> Seq.map (prefix "Hello")
and get this result:
val it : seq =
  seq ["Hello, Joe"; "Hello, Sue"; "Hello, Mary"; "Hello, Bill"]