Skip to content

Instantly share code, notes, and snippets.

@jcolebrand
Created November 16, 2011 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcolebrand/1371904 to your computer and use it in GitHub Desktop.
Save jcolebrand/1371904 to your computer and use it in GitHub Desktop.
Just to be an ass
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