예제 #1
0
파일: Monad.cs 프로젝트: kogoia/Types
        public static M1 Bind <M0, M1, T1, T2>(this TList <T1> .ParentType <M0> monad, Func <T1, IMonad <M1, EmptyList, T2> > m)
            where M0 : IMonad <M0, EmptyList, T1>
            where M1 : TList <T2> .ParentType <M1>, IMonad <M1, EmptyList, T2>
            where T1 : class
            where T2 : class
        {
            var obj = m(monad.First());

            return(new Factory <M1, IEnumerable <T2> >(
                       obj,
                       monad
                       .SelectMany(
                           x => new Factory <M1, IEnumerable <T2> >(
                               obj,
                               ((M1)m(x)).Select(y => y)
                               ).Instance()
                           )
                       .Select(x => x)
                       )
                   .Instance());
        }