I have this C# code:
const int bufferLen = 4096;
byte[] buffer = new byte[bufferLen];
int count = 0;
while ((count = stream.Read(buffer, 0, bufferLen)) > 0)
{
outstream.Write(buffer, 0, count);
}
I need to rewrite it in F#. I can do it like this:
let bufferLen : int = 4096
let buffer : byte array = Array.zeroCreate bufferLen
let count : int = 0
let mutable count = stream.Read(buffer, 0, bufferLen)
if count > 0 then
outstream.Write(buffer, 0, count)
while (count > 0) do
count <- stream.Read(buffer, 0, bufferLen)
outstream.Write(buffer, 0, count)
But may be there is a more functional way ?
Aside from Patryk's point on comment:
It's a really imperative problem so it will not get much prettier.
The only thing I would try to change is the repeated read/writes - maybe like this: