///<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.