Beispiel #1
0
        public IEnumerable <TRes> Join <TRVec, TR, TRes>(VectorBase <TRVec, TR> rightVec, Func <string, T, TR, TRes> resultSelector)
            where TRVec : VectorBase <TRVec, TR>, new()
        {
            var rightEnum = rightVec?.Items ?? Enumerable.Empty <VectorItem <TR> >();

            foreach (var grp in this.Select(i => (left: true, server: i.ServerId, leftval: i.Value, rightval: default(TR)))
                     .Concat(rightEnum.Select(i => (left: false, server: i.ServerId, leftval: default(T), rightval: i.Value)))
                     .GroupBy(t => t.server, StringComparer.InvariantCultureIgnoreCase))
            {
                // note that this validates that the same server ID is not present multiple times in either.
                var leftval  = grp.SingleOrDefault(t => t.left).leftval;
                var rightval = grp.SingleOrDefault(t => !t.left).rightval;
                var serverId = grp.Key;
                if (string.IsNullOrWhiteSpace(serverId))
                {
                    throw new InvalidOperationException("Vector server IDs may not be empty.");
                }

                yield return(resultSelector(serverId, leftval, rightval));
            }
        }
Beispiel #2
0
 public IEnumerable <TRes> Join <TRVec, TR, TRes>(VectorBase <TRVec, TR> rightVec, Func <T, TR, TRes> resultSelector)
     where TRVec : VectorBase <TRVec, TR>, new()
 {
     return(Join(rightVec, (_, l, r) => resultSelector(l, r)));
 }