# QuickCast to Delegates

> [`Tango.Functional.QuickDelegateCast`](https://github.com/gabrielschade/Tango/blob/master/Tango/Tango/Functional/QuickDelegateCast.cs)

this *static* class contains methods to transform a named method to its respectively delegate `Func` or `Action`.

It turns way more easily to uses the extensions to [`Curry`](https://github.com/gabrielschade/tango/tree/379cc4a38ae47796971eb875ec66e7dc053a9081/Functional/Currying.html) and [`Partial Application`](https://github.com/gabrielschade/tango/tree/379cc4a38ae47796971eb875ec66e7dc053a9081/Functional/PartialApplication.html).

## Methods

| Name | Parameters                         | Returns                   | Description                    |
| ---- | ---------------------------------- | ------------------------- | ------------------------------ |
| F    | Func\<TResult> function            | Func\<TResult>            | Casts a function as a delegate |
| F    | Func\<T, TResult> function         | Func\<T, TResult>         | Casts a function as a delegate |
| F    | Func\<T, T2, TResult> function     | Func\<T, T2, TResult>     | Casts a function as a delegate |
| F    | Func\<T, T2, T3, TResult> function | Func\<T, T2, T3, TResult> | Casts a function as a delegate |
| F    | Func\<T, T2, TResult> function     | Func\<T, T2, TResult>     | Casts a function as a delegate |
| A    | Action function                    | Action                    | Casts a function as a delegate |
| A    | Action\<T> function                | Action\<T>                | Casts a function as a delegate |
| A    | Action\<T, T2> function            | Action\<T, T2>            | Casts a function as a delegate |
| A    | Action\<T, T2, T3> function        | Action\<T, T2, T3>        | Casts a function as a delegate |
| A    | Action\<T, T2, T3, T4> function    | Action\<T, T2, T3, T4>    | Casts a function as a delegate |

## Usage

The several overloads avaliable in this class can be used to cast a named function into its respectively delegate.

Unfortunately, because of the language limitations is not possible (until now) treat an named function directly as an delegate.

See the code bellow:

```csharp
int SampleAdd(int value1, int value2)
    => value1 + value2;

SampleAdd.Curry();
SampleAdd.PartialApply(1);
```

The attemp to uses `Curry` and `PartialApply` will causes an compile error, because SampleAdd isa method and can't be used in this specific context.

To uses these extensions is necessary to cast the named function into a delegate.

```csharp
Func<int, int, int> sampleAddAsDelegate = SampleAdd;

sampleAddAsDelegate.Curry();
sampleAddAsDelegate.PartialApply(1);
```

With this class, is possible to create a more quick version of this cast.

To do this inline cast, you need to follow the steps bellow:

1. Add a command of `using static Tango.Functional.QuickDelegateCast`;
2. Uses the correct overload described in `Methods` subsection.

```csharp
using static Tango.Functional.QuickDelegateCast;

int SampleAdd(int value1, int value2)
    => value1 + value2;

F<int, int, int>(SampleAdd).Curry();
F<int, int, int>(SampleAdd).PartialApply(1);
```

Through the `F()` and `A()` sintax is possible to cast a named function to its respectively delegate and use its extensions.

The fundamentals about Currying and Partial Application can be find in [Fundamentals > Currying and Partial Application](https://github.com/gabrielschade/tango/tree/379cc4a38ae47796971eb875ec66e7dc053a9081/Concepts/Currying%20and%20Partial%20Application.html).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://gabriel-schade-cardoso.gitbook.io/tango/functional/cast-rapido-para-delegates.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.
