An F# library that provides an easy way to write code that writes code
$ dotnet add package StringBufferAn F# computation expression for writing code with code
| GitHub Actions |
|---|
| Package | Stable | Prerelease |
|---|---|---|
| StringBuffer |
Install the latest version from https://www.nuget.org/packages/StringBuffer/
Then use stringBuffer and indent to write your code that writes code.
stringBuffer {
"let square x ="
indent {
"x * x"
}
}
stringBuffer and indent can both be nested in each other and will correctly produce output indented as expected.
let namespaces = seq {
"System"
"System.IO"
}
let formattedCode = stringBuffer {
namespaces |> Seq.map (fun ns -> "open " + ns)
""
"module MyModule"
indent {
"let LifeUniverseAndEverything () ="
indent {
"42"
}
}
}
open System
open System.IO
module MyModule
let LifeUniverseAndEverything () =
42
Make sure the following requirements are installed on your system:
or