どう書く? - 条件を満たす行を取り除く

条件を満たす行を取り除く - どう書く? org

最近覚えたアクティブパターンを半ば無理やり使ってみました。

open System.IO;
open System.Text.RegularExpressions

let (|IsMatch|_|) (str : string) =
  let regex = new Regex(@"^#.+")
  if regex.IsMatch(str) then
    None
  else
    Some(str)

let (|IsEnd|_|) (str : string) =
  if str = null then
    Some("Null")
  else
    None

[<EntryPoint>]
let main(args : string[]) =
  let sr = new StreamReader(@"c:\work\in.txt")
  let sw = new StreamWriter(@"c:\work\out.txt")

  let rec func() =
    let lineStr = sr.ReadLine()
    match lineStr with
    | IsEnd a ->
      sw.Close();
      sr.Close();
    | IsMatch s ->
      sw.WriteLine(s);
      func()
    | _ -> 
      func()
  func()
  0