News for hackers. Stuff that matters.
Re:Functional isn't always better by Strilanc on Friday October 07, 2011 @12:15PM (#3084622)
Adding to the list of simple implementations, here's one in C#:

    list.SelectMany((e, i) => list.Skip(i+1).Select(f => Tuple.Create(e, f)))
I think the author started with the wrong idea and didn't backtrack far enough before giving up.
Re:Functional isn't always better by Dn_Ab on Friday October 07, 2011 @02:39PM (#3085287)
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