예제 #1
0
        /// <summary>
        /// Returns a composition of the two morphisms.
        /// </summary>
        public static IMorphism <A, C> Compose <A, B, C>(IMorphism <A, B> m1, IMorphism <B, C> m2)
        {
            var mappings = m1.Domain.Select(a =>
            {
                var bo = m1.Apply(a);
                var co = bo.FlatMap(b => m2.Apply(b));
                return(co.Map(c => Product2.Create(a, c)));
            });

            return(Create(mappings.Flatten()));
        }
예제 #2
0
 public IsoMorphism(IEnumerable <IProduct2 <A, B> > mappings)
     : base(mappings)
 {
     Inverse = Morphism.Create(mappings.Select(m => Product2.Create(m.ProductValue2, m.ProductValue1)));
 }
예제 #3
0
 /// <summary>
 /// Returns an identity morphism of the specified values.
 /// </summary>
 public static IMorphism <A, A> Identity <A>(IEnumerable <A> values)
 {
     return(Create(values.Select(v => Product2.Create(v, v))));
 }
예제 #4
0
 /// <summary>
 /// Converts the specified normalized function back to a standard function used in .NET.
 /// </summary>
 public static Func <T1, T2, TResult> Denormalized <T1, T2, TResult>(this Func <IProduct2 <T1, T2>, TResult> f)
 {
     return((t1, t2) => f(Product2.Create(t1, t2)));
 }