# Map

Creates a new `Option<T>` whose value is the result of applying the given `mapping` function to `Option<T>.Some` value.

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

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

## Usage

This function is usually used to modify an optional value by applying a given regular function. For instance, With this method is possible to apply an function that receive an `int` to an `Option<int>`.

This function uses the `Match` method to get the encapsulated value by `Option<T>`, applies the `mapping` function and encapsulate the result.

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

```csharp
Option<int> optionValue = 4;
Option<int> result = optionValue.Map(value => value * 2);

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

&#x20;**When the option value IsSome and the Map function modifies its type**

```csharp
Option<int> optionValue = 4;
Option<string> result = optionValue.Map(value => value.ToString());

//result.IsSome = true
//result.Some = "4"
```

&#x20;**When the option value IsSome (with named function)**

```csharp
int SquareAndDouble(int value)
{
    return value * value * 2;
}

Option<int> optionValue = 4;
Option<int> result = optionValue.Map(SquareAndDouble);

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

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

```csharp
Option<int> optionValue = Option<int>.None();
Option<int> result = optionValue.Map(value => value * 2);

//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/map.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.
