title: generalizing 'using' in a functional way
body: <p>I've been going through my c# code and trying to convert the majority of it to be more functional. </p>
  
  <p>How do you convert this <strong>using</strong> expression into a more functional-style pattern?</p>
  
  <pre><code>    using (var stream = File.OpenWrite(Path.Combine(settingsFolder, settingsFilename)))
      using (var writer = new someClass(stream))
      {
          writer.Write(settings);
      }
  </code></pre>
  
  <p>I'm trying to use this functional pattern (replacing <strong>using</strong> with this <strong>Disposable):</strong></p>
  
  <pre><code>public static class Disposable
  {
      public static TResult Using&lt;TDisposable, TResult&gt;(
          Func&lt;TDisposable&gt; factory,
          Func&lt;TDisposable, TResult&gt; map)
          where TDisposable : IDisposable
      {
          using (var disposable = factory())
          {
              return map(disposable);
          }
      }
  }
  </code></pre>
  
  <p><strong>Will this pattern not work since the class File is static and sealed?</strong> </p>