-
-
Save isaacabraham/78fe32f350dcacac2d7fd86144789258 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 (str: string) = | |
match str with | |
| str when str.Length < 5 -> Error StringTooShort | |
| str -> Ok str | |
let infrastructure text = | |
let path = Path.Combine(Path.GetTempPath(), "my-text.txt") | |
printfn $"Storing at {path}" | |
File.WriteAllText(path, text) | |
let console () = | |
printfn "What message do you want to store?" | |
match Console.ReadLine() with | |
| null | "" -> None | |
| str -> Some str | |
console () | |
|> Option.map application | |
|> Option.defaultValue (Error StringMissing) | |
|> Result.map infrastructure | |
|> printfn "Stored successfully? %A" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Actually, figured that Ctrl-Z on Windows (EOF) makes the string null, so
console
would returnSome null
...