Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding new member to CsvProvider type in F#

I'm reading a CSV file in F# with CsvProvider from FSharp.Data. Is there a way to add new (calculated) columns without transforming it into an entirely new type?

open FSharp.Data

type Person = CsvProvider<"persons.csv">
let personData = Person.Load "persons.csv"

If Person has a member called YearOfBirth then is it possible to add a new member to it called Age that would have the calculated value of (DateTime.Now.Year - YearOfBirth) for all CSV rows?

like image 857
Bedford Avatar asked Apr 15 '16 20:04

Bedford


1 Answers

It depends on what you want, but this may work:

type Person.Row with
    member this.Age = DateTime.Now.Year - this.YearOfBirth
like image 60
kvb Avatar answered Sep 24 '22 01:09

kvb