Advertisement
Guest User

Untitled

a guest
Jun 18th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.67 KB | None | 0 0
  1. // Learn more about F# at http://fsharp.net
  2. // See the 'F# Tutorial' project for more help.
  3.  
  4. open FSharp.Data
  5. open System
  6.  
  7.  
  8.  type Record = {voivoship : Option<int>;  district : Option<int>; community:Option<int>; rozd:Option<int>; name: Option<string>; addinf: Option<string> }
  9.  
  10.  type InputXml = XmlProvider<"Terc.xml">
  11.  
  12. [<EntryPoint>]
  13. let main argv =
  14.  
  15.     let createRecord =
  16.         {
  17.             voivoship = None
  18.             district = None
  19.             community = None
  20.             rozd = None
  21.             name = None
  22.             addinf = None
  23.         }
  24.  
  25.     let addCol name number string record =
  26.         match name with
  27.         | "WOJ" -> { record with voivoship = number }
  28.         | "POW" -> { record with district = number }
  29.         | "GMI" -> { record with community = number }
  30.         | "RODZ" -> { record with rozd = number }
  31.         | "NAZWA" -> { record with name = string }
  32.         | "NAZDOD" ->  { record with addinf = string }
  33.         | _ -> record
  34.  
  35.  
  36.     let tercs = InputXml.GetSample()
  37.  
  38.     let createRecordBasedOnRow cols =
  39.         let rec iterateCols record (cols:List<InputXml.Col>) =
  40.             match cols with
  41.                 | head::tail -> iterateCols (addCol head.Name head.Number head.String record) tail
  42.                 | [] -> record
  43.  
  44.         iterateCols createRecord cols
  45.  
  46.     let records =
  47.         seq {
  48.             for row in tercs.Rows do      
  49.                 yield (createRecordBasedOnRow (row.Cols |> Array.toList))
  50.             }
  51.  
  52.     for r in records do
  53.         match r.voivoship with
  54.         | None -> ()
  55.         | Some s -> printfn "%i" s
  56.        
  57.     Console.Read();
  58.     0 // return an integer exit code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement