Example #1
0
        /// <summary>
        /// See also https://msdn.microsoft.com/en-us/library/bb534675(v=vs.110).aspx
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="A"></typeparam>
        /// <typeparam name="B"></typeparam>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="reduceA"></param>
        /// <param name="reduceB"></param>
        /// <returns></returns>
        public static Bag <KeyValuePair <K, Pair <Option <A>, Option <B> > > > Join <K, A, B>(
            this Bag <KeyValuePair <K, A> > a,
            Bag <KeyValuePair <K, B> > b,
            Func <A, A, A> reduceA,
            Func <B, B, B> reduceB)
        {
            var ap = a.SelectValue(p => p.Option().WithB(new Option <B>()));
            var bp = b.SelectValue(p => new Option <A>().WithB(p.Option()));
            var ab = ap.DisjointUnion(bp);
            var r  = reduceA.OptionBinaryFunc().PairBinaryFunc(reduceB.OptionBinaryFunc());

            return(ab.GroupBy(r));
        }
Example #2
0
 public static Bag <KeyValuePair <K, Pair <A, B> > > Right <K, A, B>(
     this Bag <KeyValuePair <K, Pair <A, Option <B> > > > bag)
 => bag.SelectValue(v => v.B.Select(b => v.A.WithB(b))).WhereValue();
Example #3
0
 public static Bag <KeyValuePair <K, Pair <A, B> > > Left <K, A, B>(
     this Bag <KeyValuePair <K, Pair <Option <A>, B> > > bag)
 => bag.SelectValue(v => v.A.Select(a => a.WithB(v.B))).WhereValue();