Projecting a list of lists efficiently in F#

后端 未结 5 632
太阳男子
太阳男子 2020-12-03 08:47

I have to do projection of a list of lists which returns all combinations with each element from each list. For example:

projection([[1]; [2; 3]]) = [[1; 2]         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 08:54

    let crossProduct listA listB listC listD listE = 
      listA |> Seq.collect (fun a -> 
      listB |> Seq.collect (fun b -> 
      listC |> Seq.collect (fun c -> 
      listD |> Seq.collect (fun d -> 
      listE |> Seq.map (fun e -> a,b,c,d,e))
    

提交回复
热议问题