开发者

F# - creating 100 objects into a List - most functional and idiomatic way

In F# what is the most functional开发者_StackOverflow 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜