Created
November 6, 2017 16:30
-
-
Save MNie/04763d141230540c8ddab1948dad3b0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type CsvParser(path: string) = | |
let _path = path | |
let index(headers: string[] option, column) = headers.Value |> Seq.findIndex (fun k -> k = column) | |
let getValuesFor(func) = | |
use data = CsvFile.Load(_path) | |
data.Rows | |
|> Seq.map(fun x -> func(data.Headers, x)) | |
|> Seq.toArray | |
member this.GetHeaders() = | |
use data = CsvFile.Load(_path) | |
if data.Headers.IsSome then data.Headers.Value else [||] | |
member this.GetValuesForColumn1() = getValuesFor(fun (headers, x) -> x.Item(index(headers, "Column 1"))) | |
member this.GetValuesForColumn2() = getValuesFor(fun (headers, x) -> x.Item(index(headers, "Column 2"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment