For your particular example, you can use:

1
2
Seq.zip3 seqa seqb seqc |> Seq.map (fun ((x,y),z,w) -> (x,y,z,w))

If you need to combine more than three sequences together, it may be worth it to define your own higher arity zip variants, such as:

1
2
let zip4 xs ys zs ws = Seq.map (fun (x,(y,z,w)) -> x,y,z,w) (Seq.zip xs (Seq.zip3 ys zs ws))
By on 4/22/2009 9:14 AM ()

Hi brett,

You could use a sequence expression

1
2
3
4
5
6
7
8
let seqa = [("raw1", 1); ("raw2", 2)]
let seqb = [1.0; 2.0]
let seqc = [11.0; 22.0]

let joined = seq { for (i, j) in seqa do
                     for x in seqb do
                       for y in seqc do
                         yield (i, j, x, y) }

If the number of seq<float>s is very large i would first put the floats in an array.

By on 4/22/2009 12:55 AM ()

Hi Felix,

I guess that is technically a join, but its giving me the Cartesian product. I want to join based on position. My Seq.map2 code does work, i just think its ugly.

Here's another way:

let joined =

seq { for i in 0..seqa.Length-1 do

yield( seqa |> Seq.nth i |> fst

, seqa |> Seq.nth i |> snd

, seqb |> Seq.nth i

, seqc |> Seq.nth i )

}

A little better, but doesn't feel so 'functional' to me...

By on 4/22/2009 8:56 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper