Home
Insert
Update snippet 'Simple example how to use option type'
Title
Description
For tutorial, example how to use option type.
Source code
let echo x = "You have to work " + x.ToString() + " hours." let ``working hours`` = let day = (int System.DateTime.Now.DayOfWeek) match day with | 0 | 6 -> None | _ -> Some(7.5) let echoHours1 = match ``working hours`` with | None -> "" | Some h -> echo h let echoHours2 = ``working hours`` |> Option.map(fun h -> echo h) let echoHours3 = ``working hours`` |> Option.map(echo)
Tags
option
option
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update