Operations with Integers

Tango.CommonOperations.IntegerOperations

This static class contains methods and properties to expose common operations to work with int types.

All members bellow returns the corresponding functions as delegates.

WARNING

All operations classes related to numerical values (int, decimal e double) contains the same properties and methods.

Properties

Name

Type

Description

Add

Func<int, int, int>

Function to represents addition operation (+) between two values.

Subtract

Func<int, int, int>

Function to represents subtraction operation (-) between two values.

Multiply

Func<int, int, int>

Function to represents multiplication operation (*) between two values.

Divide

Func<int, int, int>

Function to represents division operation (/) between two values.

Add3

Func<int, int, int, int>

Function to represents addition operation (+) between three values.

Subtract3

Func<int, int, int, int>

Function to represents subtraction operation (-) between three values.

Multiply3

Func<int, int, int, int>

Function to represents multiplication operation (*) between three values.

Divide3

Func<int, int, int int>

Function to represents division operation (/) between three values.

Methods

Name

Parameters

Returns

Description

AddWith

int value

Func<int, int>

Function to represents addition operation (+) between two values, applying first value as partial application on Add method.

SubtractWith

int value

Func<int, int>

Function to represents subtraction operation (-) between two values, applying first value as partial application on Subtract method.

MultiplyWith

int value

Func<int, int>

Function to represents multiplication operation (*) between two values, applying first value as partial application on Multiply method.

DivideWith

int value

Func<int, int>

Function to represents multiplication operation (/) between two values, applying first value as partial application on Divide method.

Add3With

int value

Func<int, int, int>

Function to represents addition operation (+) between three values, applying first value as partial application on Add3 method.

Add3With

int value

int value2

Func<int, int>

Function to represents addition operation (+) between three values, applying first and second values as partial application on Add3 method.

Subtract3With

int value

Func<int, int, int>

Function to represents subtraction operation (-) between three values, applying first value as partial application on Subtract3 method.

Subtract3With

int value

int value2

Func<int, int>

Function to represents subtraction operation (-) between three values, applying first and second values as partial application on Subtract3 method.

Multiply3With

int value

Func<int, int, int>

Function to represents multiplication operation (*) between three values, applying first value as partial application on Multiply3 method.

Multiply3With

int value

int value2

Func<int, int>

Function to represents multiplication operation (*) between three values, applying first and second values as partial application on Multiply3 method.

Divide3With

int value

Func<int, int, int>

Function to represents division operation (/) between three values, applying first value as partial application on Divide3 method.

Divide3With

int value

int value2

Func<int, int>

Function to represents division operation (/) between three values, applying first and second values as partial application on Divide3 method.

Usage

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

Add

int value = 10;
int value2 = 5;
int result = IntegerOperations.Add(value, value2);

//result= 15

Subtract

int value = 10;
int value2 = 5;
int result = IntegerOperations.Subtract(value, value2);

//result= 5

Multiply

int value = 10;
int value2 = 5;
int result = IntegerOperations.Multiply(value, value2);

//result= 50

Divide

int value = 10;
int value2 = 5;
int result = IntegerOperations.Divide(value, value2);

//result= 2

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.

AddWith

int value = 10;
int value2 = 5;
Func<int,int> addWith= IntegerOperations.AddWith(value);
int result = addWith(value2);

//result= 15

You can also use it as a chainable operation:

int value = 10;
int value2 = 5;
int result = IntegerOperations.AddWith(value)(value2);

//result= 15

The ~With operations are available to the four main operations, all of them follows the same caracteristics that the previous example.

You can use these methods as Partial Applications if you needs to.

Add3With

int value = 10;
int value2 = 5;
int value3 = 5
Func<int, int, int> addWith2= IntegerOperations.Add3With(value);
int result = addWith2(value2, value3);

//result= 20

You can also use it as a chainable operation:

int value = 10;
int value2 = 5;
int value3 = 5
int result = IntegerOperations.Add3With(value)(value2, value3);

//result= 20

You can use the two parameters overload as well:

int value = 10;
int value2 = 5;
int value3 = 5
Func<int, int> addWith= IntegerOperations.Add3With(value, value2);
int result = addWith(value3);

//result= 20
int value = 10;
int value2 = 5;
int value3 = 5
int result = IntegerOperations.Add3With(value,value2)(value3);

//result= 20

Last updated