views:

41

answers:

1

I have IEnumerable<A> and IEnumerable<B> I want to Group Join based on whether A.Test(B) returns true.

The keyselector funcs do not seem to do this as the KeySelectors need to return keys of the same type so that they can be checked for equality.

Is there something I'm missing here?

+1  A: 

You're right, GroupJoin can't really handle this case. Will this workaround do?

var res = from aInstance in aSequence 
          select new {
                       A = aInstance,
                       MatchingBs = bSequence.Where(bInstance => aInstance.Test(bInstance))
                     };
Ani
Yes, it will. For all practical purposes it will do. Normally I wouldn't give this a second glance. I'm just a bit wary after reading "Functional Programming for the real World". Damn book doesn't let me be at ease when the predicate and resultselector is mixed together. I can't believe that I'm actually visualizing a currying func (predicate->resultselector)in C# just to stroke my newfound functional sensitivities. Not seriously, though. If anything, it will be my own overload of GroupJoin, naturally. Thanks for responding.
Tormod
@Tormod: A purist, I see!
Ani
A wannabe purist :)
Tormod