Operations with Booleans

Tango.CommonOperations.BoolOperations

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.

Not

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

//result= false

Or

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

//result = true

And

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.

OrWith

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:

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

//result = true

AndWith

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:

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

//result = false

results matching ""

    No results matching ""