# Extensions

## ParallelProcessToDictionary (DataTable)

This extension method processes a DataTable in parallel and returns a `ConcurrentDictionary` containing the results, with the keys generated by the provided callback.

#### Example:

```csharp
DataTable dataTable = GetDataTable();
ConcurrentDictionary<int, DataRow> resultDictionary = dataTable.ParallelProcessToDictionary(row => (int)row["Id"]);
```

## ParallelProcessToDictionary (IEnumerable)

This extension method processes an IEnumerable in parallel and returns a `ConcurrentDictionary` containing the results, with the keys generated by the provided callback.

#### Example:

```csharp
IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
ConcurrentDictionary<int, int> resultDictionary = numbers.ParallelProcessToDictionary(number => new KeyValuePair<int, int>(number, number * 2));
```

## ParallelProcessToGroupProcessor

This extension method processes an IEnumerable in parallel to a new grouped processor.

#### Example:

```csharp
IEnumerable<MyClass> myClasses = GetMyClasses();

GroupProcessor<MyClass, string> groupProcessor = myClasses.ParallelProcessToGroupProcessor((x) => x.groupByField);
```

## ParallelProcessToSingleProcessor

Converts an IEnumerable to a SingleProcessor using a provided callback function.

#### Example:

```csharp
IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
Expression<Func<int, int>> callback = x => x * 2;

SingleProcessor<int, int> singleProcessor = numbers.ParallelProcessToSingleProcessor(callback);
```

## ParallelProcessToBag

This extension method processes an IEnumerable in parallel and returns a `ConcurrentBag` containing the transformed items, with the transformation function provided by the callback.

#### Example:

```csharp
IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
ConcurrentBag<string> resultBag = numbers.ParallelProcessToBag(number => $"Number: {number}");
```

## ParallelProcessToBag (DataTable)

This extension method processes a DataTable in parallel and returns a `ConcurrentBag` containing the transformed items, with the transformation function provided by the callback.

#### Example:

```csharp
DataTable dataTable = GetDataTable();
ConcurrentBag<int> resultBag = dataTable .ParallelProcessToBag(row => (int)row["Id"]);
```

##

## ParallelProcessToBag (with ExceptionRows)

This extension method processes an IEnumerable in parallel, returns a `ConcurrentBag` containing the transformed items, and handles exceptions using the provided callback.

#### Example:

```csharp
IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
ConcurrentBag<string> resultBag = numbers.ParallelProcessToBag(
    number => $"Number: {number}",
    exceptions => {
        foreach (var exception in exceptions)
        {
            Console.WriteLine($"Error: {exception.exception.Message}, Item: {exception.Item}");
        }
    });

```

## ParallelProcess (ConcurrentBag)

This extension method processes a `ConcurrentBag` in parallel, invoking the provided callback for each item.

#### Example:

```csharp
ConcurrentBag<int> numbers = new ConcurrentBag<int>(new List<int> { 1, 2, 3, 4, 5 });
numbers.ParallelProcess(number => Console.WriteLine($"Processing number: {number}"));
```

## ParallelProcess (ConcurrentDictionary)

This extension method processes a `ConcurrentDictionary` in parallel, invoking the provided callback for each key-value pair.

#### Example:

```csharp
ConcurrentDictionary<int, string> dictionary = new ConcurrentDictionary<int, string>();
dictionary[1] = "One";
dictionary[2] = "Two";
dictionary[3] = "Three";
dictionary.ParallelProcess(pair => Console.WriteLine($"Processing pair: {pair.Key}, {pair.Value}"));
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.perigee.software/core-modules/perigee-in-parallel/extensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
