Over a million developers have joined DZone.

.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


Published at DZone with permission of Justin Etheredge. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}