Skip to content

Instantly share code, notes, and snippets.

@Orcomp
Last active December 20, 2015 15:39
Show Gist options
  • Select an option

  • Save Orcomp/6155383 to your computer and use it in GitHub Desktop.

Select an option

Save Orcomp/6155383 to your computer and use it in GitHub Desktop.
I am trying to print a list of objects as a comma separated string
[<StructuredFormatDisplay("{Print}")>]
type StockLevel =
{Product:string; Quantity:int; Date:DateTime}
override m.ToString() = String.Format("{0},{1},{2}", m.Product, m.Quantity, m.Date)
member m.Print = m.ToString()
let rand = new Random()
let stockLevelCreator (x:int) (y:int) = {Product= "A" + y.ToString(); Quantity=rand.Next(0,100); Date= DateTime.Now.AddDays(x |> float)}
let stockLevels =
[for product in [1..2] do
for days in [1..10] do
yield stockLevelCreator days product]
stockLevels |> List.map (fun o -> printfn "%s" (o.ToString()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment