.NET Parallel Extension Like Functionality Added To The Dizzy - Functional List Library
I have added an "AsParallel()" method to Dizzy which mimics the way that the Parallel Extensions to the .net framework works. So, if you want to call a parallel map function you simply need to do this:
list.AsParallel().Map(n => n.ToUpper());
The AsParallel() method just looks like this:
public static IParallelEnumerable<T> AsParallel<T>(this IEnumerable<T> list)
{
return new ParallelEnumerable<T>(list);
}
As you can see, it just takes an IEnumerable<T> and replaces it with a IParallelEnumerable<T>. This Interface/Class combo doesn't provide any sort of work, it is just a flag to use the Parallel version of methods. Currently "Map" is the only method with a parallel version. The ParallelEnumerable class just looks like this:
public class ParallelEnumerable<T> : IParallelEnumerable<T>
{
private IEnumerable<T> enumerable;
public ParallelEnumerable(IEnumerable<T> list)
{
if (list == null) throw new ArgumentNullException("list");
this.enumerable = list;
}
IEnumerator IEnumerable.GetEnumerator()
{
return this.enumerable.GetEnumerator();
}
public IEnumerator<T> GetEnumerator()
{
return this.enumerable.GetEnumerator();
}
}
Read this rest of this post at CodeThinked.com
- Login or register to post comments
- 1149 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)














