开发者

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

开发者 https://www.devze.com 2023-02-22 21:50 出处:网络
In F# what is the most functional开发者_StackOverflow and idiomatic way of creating or \"newing up\" 100 new objects into a List.

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

精彩评论

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

关注公众号