Created
August 7, 2025 14:47
-
-
Save mhuisi/2da80dcf2055635bb6afb6d069b79415 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| def normalize (s : String) : String := Id.run do | |
| let s := s.dropWhile (·.isWhitespace) |>.dropRightWhile (·.isWhitespace) | |
| let lines := s.splitOn "\n" | |
| |>.map (fun s => s.dropWhile (·.isWhitespace) |>.dropRightWhile (·.isWhitespace)) | |
| let mut r := "" | |
| for i in [0:lines.length-1] do | |
| let line := lines[i]! | |
| if line.endsWith "." || line.endsWith ":" then | |
| r := r ++ line ++ "\\n" | |
| else if line == "" then | |
| r := r ++ "\\n" | |
| else | |
| r := r ++ line ++ " " | |
| r := r ++ lines[lines.length-1]! | |
| return s!"\"description\": \"{r}\"" | |
| def printNormalized (s : String) : IO Unit := do | |
| IO.println <| normalize s | |
| def s := " | |
| " | |
| #eval printNormalized s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment