title: What's a functional replacement for if-then statements?
body: <p>I've been learning F# and functional programming and trying to do things the functional way. However, when it comes to rewriting some code I'd already written in C# I get stuck at simple if-then statements (ones that only do something, not return a value). I know you can pull this off in F#:</p>
  
  <pre><code>if expr then do ()
  </code></pre>
  
  <p>However, I thought this was an imperative approach to coding? Maybe I've not learned enough about functional programming, but it doesn't seem functional to me. I thought the functional approach was to compose functions and expressions, not simply execute statements one after the other which is what if-then seems to encourage.</p>
  
  <p>So, am I missing something and if-then is perfectly fine in the functional world? If not, what is the functional equivalent of such a statement? How could I take an if-then and turn it functional?</p>
  
  <p>Edit: I might've asked the wrong question (sorry, still fairly new to functional programming): Let's take a real world example that made me even ask this:</p>
  
  <pre><code>if not &lt;| System.String.IsNullOrWhiteSpace(data) then do
      let byteData = System.Text.Encoding.Unicode.GetBytes(data)
      req.ContentLength &lt;- int64 byteData.Length
      let postStream : System.IO.Stream = req.GetRequestStream()
      postStream.Write(byteData, 0, byteData.Length)
      postStream.Flush()
      postStream.Dispose()
  </code></pre>
  
  <p>The body of that if-then doesn't return anything, but I don't know how I could make this more functional (if that's even possible). I don't know the proper technique for minimizing imperative code. Given F#'s nature it's fairly easy to just transport my C# directly, but I'm having difficulties turning it functional. Every time I reach such an if statement in C#, and I'm trying to transport it to F#, I get discouraged that I can't think of a way to make the code more functional.</p>