如何在 F# 中将 id 附加到序列?
我有一个 seq<'A>
。我想将其映射到 seq<(int, 'A)>
,其中整数是从 0 开始的自动生成的值序列。我知道我可以使用可变计数器来做到这一点和一个循环,但是有没有更优雅的方法来做到这一点,也许使用 Seq.map ?
I have a seq<'A>
. I want to map this to a seq<(int, 'A)>
, where the integer is an auto-generated sequence of values starting at 0. I know I can do this with a mutable counter and a loop, but is there a more elegant way to do this, perhaps using Seq.map
?
查看
Seq.mapi
:http://msdn。 microsoft.com/en-us/library/ee340431.aspxCheck out
Seq.mapi
: http://msdn.microsoft.com/en-us/library/ee340431.aspx