What about
let c = a |> Seq.collect (fun (v,i) -> [1..i] |> Seq.map (fun x -> v))
I do not know a library function similar to Enumerable.Repeat; if someone knows one, add a comment.
EDIT
I found a library function similar to Enumerable.Repeat, although it is in the List module:
let c = a |> Seq.collect (fun (v,i) -> List.replicate iv)
This would be more elegant if the pairs in the original sequence were canceled:
let c = a |> Seq.collect ((<||) List.replicate)
So, it seems that Enumerable.Repeat (as in the accepted answer) really makes the best decision, since its alternating argument matches the elements of the sequence:
let c = a |> Seq.collect Enumerable.Repeat
If anyone knows of a similar elegant solution that remains in the F # library, add a comment; thanks.
phoog
source share