#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
#endregion
namespace Stl
{
public delegate T Generator<T>();
public delegate T UnaryFunction<Arg, T>(Arg x);
public delegate T BinaryFunction<Arg1, Arg2, T>(Arg1 x, Arg2 y);
// public delegate bool Predicate<T>(T obj);
public delegate bool Relation<T>(T x,T y);
namespace Functional
{
public static class Plus : object
{
public static decimal Decimal(decimal x, decimal y)
{
return x + y;
}
public static double Double(double x, double y)
{
return x + y;
}
public static float Float(float x, float y)
{
return x + y;
}
public static long Int64(long x, long y)
{
return x + y;
}
public static int Int32(int x, int y)
{
return x + y;
}
}
public static class Minus : object
{
public static decimal Decimal(decimal x, decimal y)
{
return x - y;
}
public static double Double(double x, double y)
{
return x - y;
}
public static float Float(float x, float y)
{
return x - y;
}
public static long Int64(long x, long y)
{
return x - y;
}
public static int Int32(int x, int y)
{
return x - y;
}
}
public static class Multiplies : object
{
public static decimal Decimal(decimal x, decimal y)
{
return x * y;
}
public static double Double(double x, double y)
{
return x * y;
}
public static float Float(float x, float y)
{
return x * y;
}
public static long Int64(long x, long y)
{
return x * y;
}
public static int Int32(int x, int y)
{
return x * y;
}
}
public static class Divides : object
{
public static decimal Decimal(decimal x, decimal y)
{
return x / y;
}
public static double Double(double x, double y)
{
return x / y;
}
public static float Float(float x, float y)
{
return x / y;
}
public static long Int64(long x, long y)
{
return x / y;
}
public static int Int32(int x, int y)
{
return x / y;
}
}
public static class Modulus : object
{
public static decimal Decimal(decimal x, decimal y)
{
return x % y;
}
public static double Double(double x, double y)
{
return x % y;
}
public static float Float(float x, float y)
{
return x % y;
}
public static long Int64(long x, long y)
{
return x % y;
}
public static int Int32(int x, int y)
{
return x % y;
}
}
public static class Negate : object
{
public static decimal Decimal(decimal x)
{
return -x;
}
public static double Double(double x)
{
return -x;
}
public static float Float(float x)
{
return -x;
}
public static long Int64(long x)
{
return -x;
}
public static int Int32(int x)
{
return -x;
}
}
public static class Binders : object
{
public static UnaryFunction<Arg2, T> Bind1st<Arg1, Arg2, T>(BinaryFunction<Arg1, Arg2, T> f, Arg1 value)
{
UnaryFunction<Arg2, T> del = delegate(Arg2 arg2)
{
return f(value,arg2);
};
return del;
}
public static UnaryFunction<Arg1, T> Bind2nd<Arg1, Arg2, T>(BinaryFunction<Arg1, Arg2, T> f, Arg2 value)
{
UnaryFunction<Arg1, T> del = delegate(Arg1 arg1)
{
return f(arg1,value);
};
return del;
}
// ça, c'est nouveau, histoire de s'amuser un peu
public static UnaryFunction<Arg, T> Compose<Arg,R,T>(UnaryFunction<R, T> f, UnaryFunction<Arg, R> g)
{
UnaryFunction<Arg, T> fog = delegate(Arg arg)
{
return f(g(arg));
};
return fog ;
}
public static BinaryFunction<Arg1, Arg2h, T> Compose2nd<Arg1,Arg2,Arg2h,T>(BinaryFunction<Arg1, Arg2, T> f, UnaryFunction<Arg2h, Arg2> h)
{
BinaryFunction<Arg1, Arg2h, T> composed = delegate(Arg1 x,Arg2h y)
{
return f(x,h(y));
};
return composed;
}
public static BinaryFunction<Arg1h, Arg2, T> Compose1st<Arg1, Arg2, Arg1h, T>(BinaryFunction<Arg1, Arg2, T> f, UnaryFunction<Arg1h, Arg1> h)
{
BinaryFunction<Arg1h, Arg2, T> composed = delegate(Arg1h x, Arg2 y)
{
return f(h(x), y);
};
return composed;
}
public static BinaryFunction<Arg2, Arg1, T> Symetric<Arg1, Arg2, T>(BinaryFunction<Arg1, Arg2, T> f)
{
BinaryFunction<Arg2, Arg1, T> composed = delegate(Arg2 x, Arg1 y)
{
return f(y,x);
};
return composed;
}
}
}
}