In F# what is the most functional and idiomatic way of creating or "newing up" 100 new objects into a List.
I guess for an example we could use DateTime as an example object.
List.init 100 (fun x -> x * 2)
Alternatively, as a list expression:
[for i in 1..100 -> new System.DateTime()]
But I think this is less idiomatic.
I would consider using
[|for i in 1..100 -> new System.DateTime() |]
since you are working with mutable data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.