5
votes

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?

1

1 Answers

6
votes

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

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