Skip to content

Instantly share code, notes, and snippets.

@chgeuer
Created April 21, 2022 10:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chgeuer/baf00cc7227f68fdb98421bc5fa2e16e to your computer and use it in GitHub Desktop.
Save chgeuer/baf00cc7227f68fdb98421bc5fa2e16e to your computer and use it in GitHub Desktop.
// F# version of https://twitter.com/gsferreira/status/1516827091127394309/
open System
open System.IO
type PotentialProcessingError = | StringMissing | StringTooShort
let application store = function
| None -> Error StringMissing
| Some (str: string) when str.Length < 5 -> Error StringTooShort
| Some str -> str |> store
let infrastructure text =
let path = Path.Combine(Path.GetTempPath(), "my-text.txt")
printfn $"Storing at {path}"
File.WriteAllText(path, text)
Ok ()
let console store =
printfn "What message do you want to store?"
match Console.ReadLine() with
| "" -> None
| str -> Some str
|> application store
console infrastructure
|> printfn "Stored successfully? %A"
Console.ReadKey() |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment