I was just reading a little about Haskell and saw its method interact
which implements the common pattern of reading input from stdin, applying a function to the strings, and writing the result back to stdout. So, for example:
interact (map toUpper)
prints back everything that comes on stdin converted to uppercase.
Is there an equivalent of this already in F#/.Net?
This functionality does not exist natively, but implementing it is easy:
let inline interact f =
printfn "%s" (f (System.Console.Readline()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With