3 ms·
The only problem here is that each time it has to skip through the entire list so far. I would write it like this in F# for equivalent generality and lazinessas
by Dn_Ab 15y ago
The only problem here is that each time it has to skip through the entire list so far. I would write it like this in F# for equivalent generality and lazinessas yours
let pairs sequence =
sequence |> Seq.fold (fun (tailList, listOfPairs) el ->
let listThusFar = tailList |> Seq.map (fun x -> el, x)
(tailList |> Seq.skip 1), listThusFar::listOfPairs)
((sequence |> Seq.skip 1),[])
|> snd |> Seq.concat