Reputation: 1186
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?
Upvotes: 5
Views: 319
Reputation: 55185
It depends on what you want, but this may work:
type Person.Row with
member this.Age = DateTime.Now.Year - this.YearOfBirth
Upvotes: 6