Adding a new member to the CsvProvider type in F #

I am reading a CSV file in F # with CsvProvider from FSharp.Data. Is there a way to add new (calculated) columns without converting it to a completely new type?

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

If Person has a member named YearOfBirth , is it possible to add to it a new member called Age , which would have a calculated value (DateTime.Now.Year - YearOfBirth) for all CSV strings?

+5
source share
1 answer

It depends on what you want, but it might work:

 type Person.Row with member this.Age = DateTime.Now.Year - this.YearOfBirth 
+6
source

Source: https://habr.com/ru/post/1247239/


All Articles