如何在F#的迭代中获取当前序列号?

时间:2022-09-18 20:36:42

Consider the following code to demonstrate the question:

请考虑以下代码来演示问题:

let sequence = Seq.initInfinite (fun _ -> "Element")
Seq.iter (fun _ -> printf "Element no: ?") sequence 

Is it in any way possible to get the current sequence number (e.g. its rank) to print?

是否有可能获得当前序列号(例如其等级)进行打印?

1 个解决方案

#1


Use the iteri function:

使用iteri功能:

let sequence = Seq.initInfinite (fun _ -> "Element")
sequence |> Seq.iteri (fun i _ -> printfn "Element no. %d" i) 

#1


Use the iteri function:

使用iteri功能:

let sequence = Seq.initInfinite (fun _ -> "Element")
sequence |> Seq.iteri (fun i _ -> printfn "Element no. %d" i)