How to get current sequence number in iteration in F #?

Consider the following code to demonstrate the question:

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

Is there any way to get the current serial number (for example, its rank) for printing?

+3
source share
1 answer

Use the iteri function :

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

Source: https://habr.com/ru/post/1711967/


All Articles