# Apply

Creates a new [`Option<T>`](https://github.com/gabrielschade/tango/tree/379cc4a38ae47796971eb875ec66e7dc053a9081/Types/Option/Introduction.html) whose value is the result of applying the given `applying` function to `Option<T>.Some` value when both `applying` and `option` are `IsSome`.

Otherwise returns an `Option<T>.None()`.

| Parameters                                                         | Returns          |
| ------------------------------------------------------------------ | ---------------- |
| <p>Option\<Func\<T, TResult>> applying</p><p>Option\<T> option</p> | Option\<TResult> |

## Usage

This function is usually used to modify an option value by using an option function.

It works like a `Map` function, but in this case both value and the function are option values.

It's possible to use `Apply` function with two different syntaxes.

1. `Apply<T, TResult>(function)`: in this case the `function` can be a regular function;
2. `Apply(optionFunction)`: in this case the `function` needs to be a option function.

&#x20;**Expliciting an optional function**&#x20;

```csharp
Func<int, int> multiply2 = value => value * 2;
Option<Func<int, int>> optionFunction = multiply2;

Option<int> optionValue = 4;
Option<int> result = optionValue.Apply(optionFunction);

//result.IsSome = true
//result.Some = 8
```

&#x20;**Using a regular function**&#x20;

```csharp
Func<int, int> multiply2 = value => value * 2;

Option<int> optionValue = 4;
Option<int> result = optionValue.Apply<int,int>(multiply2);

//result.IsSome = true
//result.Some = 8
```

&#x20;**When the option function IsNone**&#x20;

```csharp
Option<Func<int, int>> optionFunction = 
    Option<Func<int, int>>.None();

Option<int> optionValue = 4;
Option<int> result = optionValue.Apply(optionFunction);

//result.IsSome = false
//result.IsNone = true
```

&#x20;**When the option value IsNone**&#x20;

```csharp
Func<int, int> multiply2 = value => value * 2;

Option<int> optionValue = Option<int>.None();
Option<int> result = optionValue.Apply<int,int>(multiply2);

//result.IsSome = false
//result.IsNone = true
```


---

# 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://gabriel-schade-cardoso.gitbook.io/tango/modules/option/apply.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.
