Skip to content

Instantly share code, notes, and snippets.

@mhuisi
Created August 7, 2025 14:47
Show Gist options
  • Select an option

  • Save mhuisi/2da80dcf2055635bb6afb6d069b79415 to your computer and use it in GitHub Desktop.

Select an option

Save mhuisi/2da80dcf2055635bb6afb6d069b79415 to your computer and use it in GitHub Desktop.
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