Created
November 16, 2011 23:48
-
-
Save jcolebrand/1371904 to your computer and use it in GitHub Desktop.
Just to be an ass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace OX.MapReduce | |
{ | |
using System; | |
using System.Linq; | |
using System.Threading.Tasks; | |
public static class MapReduce | |
{ | |
public static Task<T> Start<U, V, T>(Func<U, V> m, Func<V[], T> r, params U[] i) { | |
return R(r, C(m, i)); | |
} | |
static Task<T> R<V, T>(Func<V[], T> r, Task<V>[] m) { | |
return Task.Factory.ContinueWhenAll(m, t => P(r, t)); | |
} | |
static T P<V, T>(Func<V[], T> r, Task<V>[] t) { | |
return r((from k in t select k.Result).ToArray()); | |
} | |
static Task<V>[] C<U, V>(Func<U, V> m, U[] i) { | |
var t = new Task<V>[i.Length]; | |
for (int j = 0; j < i.Length; ++j) t[j] = Task.Factory.StartNew(() => m(i[j])); | |
return tasks; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment