Esempio n. 1
0
        public static IArrow First <C>(this IArrow arr)
        {
            /*
             * A slightly messy way of simplifying First using the IArrow interface and determining
             * the types of the input arrow at runtime, so that it doesn't take three type
             * parameters.
             * Horrific code btw.
             */

            Type a = arr.a;
            Type b = arr.b;
            Type c = typeof(C);

            Type inputTupleType  = typeof(Tuple <,>).MakeGenericType(a, c);
            Type outputTupleType = typeof(Tuple <,>).MakeGenericType(b, c);
            Type resultType      = typeof(Arrow <,>).MakeGenericType(inputTupleType, outputTupleType);

            Type funcType = typeof(Func <,>).MakeGenericType(inputTupleType, outputTupleType);

            Type[] constructorTypes = new Type[1];
            constructorTypes[0] = funcType;
            ConstructorInfo constructor = resultType.GetConstructor(constructorTypes);

            dynamic[] parameters = new dynamic[1];
            parameters[0] = new Func <Tuple <dynamic, dynamic>, Tuple <dynamic, dynamic> >((Tuple <dynamic, dynamic> x) => new Tuple <dynamic, dynamic>(arr.Invoke(x.Item1), x.Item2));

            return((IArrow)constructor.Invoke(parameters));
        }