当前位置:软件学习 > 其它软件 >>

拆分奇偶数

拆分奇偶数

open System
open System.IO

let a = seq{1..10}

let writeToFile filename obj =
  using(File.AppendText(filename)) (fun file1 ->
    file1.WriteLine("{0}", obj.ToString() )
  )

let e =
  a
  |> Seq.map(fun i -> i,i*i)
  |> Seq.iter(fun (x, y) ->
                    match x with
                    //| x when x%2 = 0 -> printfn "%A" x
                    | x when x%2 = 0 -> writeToFile "偶数.txt" (x,y)
                    //| x when x%2 = 1 -> printfn "%A" x
                    | x when x%2 = 1 -> writeToFile "奇数.txt" (x,y)
                    | _ -> ())


摘自 hadstj的专栏
补充:软件开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,