Created
April 21, 2022 10:31
-
-
Save chgeuer/baf00cc7227f68fdb98421bc5fa2e16e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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