Line Filters in Idris
Our example demonstrates a line filter in Idris that reads input from stdin, processes it, and prints a derived result to stdout. This particular filter capitalizes all input text.
This program does the following:
We import necessary modules for file I/O and string manipulation.
In the
main
function, we usegetContents
to read all input from stdin.We then use
map
to apply ourprocessLine
function to each line of the input.The
processLine
function simply converts each line to uppercase usingtoUpper
.Finally, we print the processed lines to stdout using
putStrLn
.
To try out our line filter, first make a file with a few lowercase lines:
Then use the line filter to get uppercase lines:
Note that in Idris, we first need to compile our program to an executable before we can run it. The -o
flag specifies the output file name.
This example demonstrates how to create a simple line filter in Idris, showcasing basic I/O operations and string manipulation. While Idris doesn’t have a built-in buffered scanner like Go, we can achieve similar functionality using the standard library functions.