# Operations with Booleans

> [`Tango.CommonOperations.BoolOperations`](https://github.com/gabrielschade/Tango/blob/master/Tango/Tango/Operations/BoolOperations.cs)

This *static* class contains methods and properties to expose common operations to work with `bool` types.

All members bellow returns the corresponding functions as delegates.

## Properties

| Name | Type                    | Description                                                           |
| ---- | ----------------------- | --------------------------------------------------------------------- |
| Not  | Func\<bool, bool>       | Function to represents the operator !.                                |
| And  | Func\<bool, bool, bool> | Function to represents the and (&&) operation between two booleans.   |
| Or   | Func\<bool, bool, bool> | Function to represents the or (\|\|) operation between two booleans.. |

## Methods

| Name    | Parameters | Returns           | Description                                                                                                               |
| ------- | ---------- | ----------------- | ------------------------------------------------------------------------------------------------------------------------- |
| AndWith | bool value | Func\<bool, bool> | Function to represents the and (&&) operation between two booleans. Applying the first boolean with Partial Application.  |
| OrWith  | bool value | Func\<bool, bool> | Function to represents the or (\|\|) operation between two booleans. Applying the first boolean with Partial Application. |

## Usage

The properties returns a delegate, so, it's possible to use it as a method.

&#x20;**Not**

```csharp
bool value = true;
bool result = BooleanOperations.Not(value);

//result= false
```

&#x20;**Or**

```csharp
bool value = true;
bool value2 = false;
bool result= BooleanOperations.Or(value, value2);

//result = true
```

&#x20;**And**

```csharp
bool value = true;
bool value2 = false;
bool result= BooleanOperations.And(value, value2);

//result = false
```

For methods you can use a little different sintax. It's necessary because these methods uses the property methods combined with Partial Application.

Because of that, you need to execute the method with the first parameter to creates a new single parameter function that perform the operation.

&#x20;**OrWith**

```csharp
bool value = true;
bool value2 = false;
Func<bool,bool> orWithPartial = BooleanOperations.OrWith(value);
bool result = orWithPartial(value2);
//result = true
```

You can also use it as a chainable operation:

```csharp
bool value = true;
bool value2 = false;
bool result = BooleanOperations.OrWith(value)(value2);

//result = true
```

&#x20;**AndWith**

```csharp
bool value = true;
bool value2 = false;
Func<bool,bool> andWithPartial = BooleanOperations.AndWith(value);
bool result = andWithPartial(value2);

//result = false
```

You can also use it as a chainable operation:

```csharp
bool value = true;
bool value2 = false;
bool result = BooleanOperations.AndWith(value)(value2);

//result = false
```
