Join() equivalent function for F# sequences
I am porting C# code to F# that makes use of LINQ's Join() extension method. Just as I use that in method call chains, I would of course like to have an F# function to pipe into.


I think that using Join() directly in C# is actually not that common, since query syntax is much nicer for that. And I think you should consider the same thing in F#: you already know about query expressions and join, so why not use that?

Though I understand that function call chains are much more flexible, so this might not be a good option for you.



Have you considered removing the resultSelector altogether? Tuples are not very idiomatic in C#, but they are in F#, so you might want to use them.



Since you want to copy the behavior of Enumerable.Join(), I would use that to implement your method.



When considering the order of parameters, I think you should think about what is the most natural usage. I think it's this:

outer
|&gt; Seq.join inner (fun o -&gt; o.OKey) (fun i -&gt; i.IKey)


This will make the order of parameters of the function quite weird, but I think it makes the most sense this way.



Putting this all together:

let join (innerSequence : 'b seq) outerKeySelector innerKeySelector (outerSequence : 'a seq) =
    outerSequence.Join(innerSequence,
        Func&lt;_, _&gt;(outerKeySelector), Func&lt;_, _&gt;(innerKeySelector),
        fun outer inner -&gt; (outer, inner))


(Those Func casts are necessary, I think it's because F#'s weird rules for implicit casting from lambdas to delegates.)