Here’s the translation of the Go code to PureScript, along with explanations in Markdown format suitable for Hugo:
Writing files in PureScript follows similar patterns to the ones we saw earlier for reading.
Try running the file-writing code:
Then check the contents of the written files:
In this PureScript version, we’ve used the Node.FS.Sync module to perform file operations. PureScript doesn’t have a direct equivalent to Go’s bufio for buffered I/O, but you can achieve similar functionality using Node.js streams if needed.
The check function for error handling is not necessary in PureScript as errors are typically handled through the type system or using the Effect monad.
Note that PureScript’s file operations are typically performed in the Effect monad, which represents side-effecting computations.
Next, we’ll look at applying some of the file I/O ideas we’ve just seen to the stdin and stdout streams.