Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I give an example in "How would I even use a Monad (in C#)?" ( http://twistedoakstudios.com/blog/Post867_how-would-i-even-u... ), assuming a hypothetical extension to the language:

    ///<summary>Pulls the monad type outside of the list type by binding across the list's elements.</summary>
    ///<remarks>Not actually possible to compile in C# today.</remarks>
    public static M<IEnumerable<T>> BindAll<M, T>(this IEnumerable<M<T>> sequence)
        where M : Monad { //<-- Type parameter M takes a type parameter T. Not currently possible.
        return sequence.Aggregate(
            M.Return(Enumerable.Empty<T>()), //<-- Static interface method. Not currently possible.
            (wrappedAccumulator, wrappedNextItem) =>
                from accumulator in wrappedAccumulator
                from item in wrappedNextItem
                select accumulator.Concat(new[] { item }).ToArray().AsEnumerable());
    }
This single method combines several apparently distinct methods: waiting for all tasks, choosing all of the combinations from a list of lists, etc.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: