Uses pattern matching with Option and Either values
Option<int> optionalValue = 10;
int value = optionalValue.Match(
methodWhenSome: number => number,
methodWhenNone: () => 0);
Either<bool, int> eitherValue = 10;
int value = eitherValue.Match(
methodWhenRight: number => number,
methodWhenLeft: boolean => 0);
Continuation flow using Then and Catch
ContinuationModule.Resolve(5)
.Then(value => value + 4)
.Then(value =>
{
if( value % 2 == 0)
return value + 5;
else
return "ERROR";
})
.Then(value => value + 10)
.Catch(fail => $"{fail} catched");
Continuation flow with pipeline operator!
ContinuationModule.Resolve(5)
> (value => value + 4)
> (value =>
{
if( value % 2 == 0)
return value + 5;
else
return "ERROR";
})
> (value => value + 10)
>= (fail => $"{fail} catched")
Powerful High Order Functions!
//IEnumerable<int> source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
IEnumerable<IEnumerable<int>> result = source.ChunkBySize(3);
//result = { {1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10} }
var (resultEvens, resultOdds) =
source.Partition(value => value % 2 == 0)
//resultEvens = { 2, 4, 6, 8, 10 }
//resultOdds = { 1, 3, 5, 7, 9 }
Uses Simple Functions as Reduction
int result = source.Scan(10, IntegerOperations.Add);
//result = {11, 13, 16, 20, 25, 31, 38, 46, 55, 65}
Uses Curry and Partial Application!
Func<int, int, int> add =
(value, value2) => value + value2;
Func<int, Func<int, int>> addCurried = add.Curry();
curriedResult = addCurried(2)(3);
Func<int, int> addPartial = add.PartialApply(2);
int partialResult = addPartial(3);
Uses QuickDelegateCast feature!
using static Tango.Functional.QuickDelegateCast;
int SampleAdd(int value1, int value2)
=> value1 + value2;
F<int, int, int>(SampleAdd).Curry();
F<int, int, int>(SampleAdd).PartialApply(1);