NumType<NUMTYPE, NUM, A, PRED> Class

NumType - inspired by Haskell's 'newtype' keyword. This is setup for numeric types,and expects a Num<A> class-instance as an argument (TInt, TDouble, etc.)

https://wiki.haskell.org/Newtype

Derive type from this one to get: Equatable, Comparable, Appendable, Foldable, Functor, Iterable: strongly typed values.

For example:

class Metres : NumType<Metres, TDouble, double> { public Metres(double x) : base(x) {} }


Will not accept null values

DECLARATION
[Serializable]
public abstract class NumType<NUMTYPE, NUM, A, PRED> : IEquatable<NUMTYPE>,
IComparable<NUMTYPE>
NAMESPACE
LanguageExt

Constructors

NumType(A)
SUMMARY

Constructor

PARAMETERS
value
A
Value to bind
DECLARATION
public ctor NumType(A value)
EXCEPTIONS
ArgumentOutOfRangeException
If argument fails to pass the predicate provided in the generic argument PRED
ArgumentNullException
Null values are not accepted

Fields

New
SUMMARY

Constructor function

DECLARATION
public static readonly Func<A, NUMTYPE> New
Value
DECLARATION
public readonly A Value

Methods

Abs()
SUMMARY

Find the absolute value of a number

DECLARATION
public virtual NUMTYPE Abs()
RETURNS
NUMTYPE
The non-negative absolute value of x
Bind(Func<A, NUMTYPE>)
SUMMARY

Monadic bind of the bound value to a new value of the same type

PARAMETERS
bind
Func<A, NUMTYPE>
Bind function
DECLARATION
[Pure]
public virtual NUMTYPE Bind(Func<A, NUMTYPE> bind)
RETURNS
NUMTYPE
CompareTo(NUMTYPE)
PARAMETERS
other
NUMTYPE
DECLARATION
[Pure]
public virtual int CompareTo(NUMTYPE other)
RETURNS
int
Divide(NUMTYPE)
SUMMARY

Divide NewType(x) and NewType(y)

PARAMETERS
rhs
NUMTYPE
Right-hand side of the operation
DECLARATION
[Pure]
public virtual NUMTYPE Divide(NUMTYPE rhs)
RETURNS
NUMTYPE
lhs / rhs
Equals(NUMTYPE)
PARAMETERS
other
NUMTYPE
DECLARATION
[Pure]
public virtual bool Equals(NUMTYPE other)
RETURNS
bool
Equals(NUMTYPE, NUMTYPE)
PARAMETERS
other
NUMTYPE
epsilon
NUMTYPE
DECLARATION
[Pure]
public virtual bool Equals(NUMTYPE other, NUMTYPE epsilon)
RETURNS
bool
Equals(object)
PARAMETERS
obj
object
DECLARATION
[Pure]
public override bool Equals(object obj)
RETURNS
bool
Exists(Func<A, bool>)
SUMMARY

Run a predicate for all values in the NumType (only ever one)

PARAMETERS
predicate
Func<A, bool>
DECLARATION
[Pure]
public virtual bool Exists(Func<A, bool> predicate)
RETURNS
bool
Fold<S>(S, Func<S, A, S>)
SUMMARY

Fold

PARAMETERS
state
S
Initial state
folder
Func<S, A, S>
Fold function
DECLARATION
public virtual S Fold<S>(S state, Func<S, A, S> folder)
RETURNS
S
Folded state and NumType bound value
FoldBack<S>(S, Func<S, A, S>)
SUMMARY

Fold back

PARAMETERS
state
S
Initial state
folder
Func<S, A, S>
Fold function
DECLARATION
public virtual S FoldBack<S>(S state, Func<S, A, S> folder)
RETURNS
S
Folded state and NumType bound value
ForAll(Func<A, bool>)
SUMMARY

Run a predicate for all values in the NumType (only ever one)

PARAMETERS
predicate
Func<A, bool>
DECLARATION
[Pure]
public virtual bool ForAll(Func<A, bool> predicate)
RETURNS
bool
GetHashCode()
DECLARATION
[Pure]
public override int GetHashCode()
RETURNS
int
Iter(Action<A>)
SUMMARY

Invoke an action that takes the bound value as an argument

PARAMETERS
f
Action<A>
Action to invoke
DECLARATION
public virtual Unit Iter(Action<A> f)
Map(Func<A, A>)
SUMMARY

Map the bound value to a new value of the same type

PARAMETERS
map
Func<A, A>
DECLARATION
[Pure]
public virtual NUMTYPE Map(Func<A, A> map)
RETURNS
NUMTYPE
Max(NUMTYPE)
PARAMETERS
rhs
NUMTYPE
DECLARATION
public virtual NUMTYPE Max(NUMTYPE rhs)
RETURNS
NUMTYPE
Min(NUMTYPE)
PARAMETERS
rhs
NUMTYPE
DECLARATION
public virtual NUMTYPE Min(NUMTYPE rhs)
RETURNS
NUMTYPE
Plus(NUMTYPE)
SUMMARY

Sum of NumType(x) and NumType(y)

PARAMETERS
rhs
NUMTYPE
Right-hand side of the operation
DECLARATION
[Pure]
public virtual NUMTYPE Plus(NUMTYPE rhs)
RETURNS
NUMTYPE
lhs + rhs
Product(NUMTYPE)
SUMMARY

Multiply NewType(x) and NewType(y)

PARAMETERS
rhs
NUMTYPE
Right-hand side of the operation
DECLARATION
[Pure]
public virtual NUMTYPE Product(NUMTYPE rhs)
RETURNS
NUMTYPE
lhs * rhs
Select(Func<A, A>)
SUMMARY

Map the bound value to a new value of the same type

PARAMETERS
map
Func<A, A>
DECLARATION
[Pure]
public virtual NUMTYPE Select(Func<A, A> map)
RETURNS
NUMTYPE
SelectMany(Func<A, NumType<NUMTYPE, NUM, A, PRED>>, Func<A, A, A>)
SUMMARY

Monadic bind of the bound value to a new value of the same type

PARAMETERS
bind
Func<A, NumType<NUMTYPE, NUM, A, PRED>>
Bind function
project
Func<A, A, A>
Final projection (select)
DECLARATION
[Pure]
public virtual NUMTYPE SelectMany(Func<A, NumType<NUMTYPE, NUM, A, PRED>> bind, Func<A, A, A> project)
RETURNS
NUMTYPE
Signum()
SUMMARY

Find the sign of x

DECLARATION
public virtual NUMTYPE Signum()
RETURNS
NUMTYPE
-1, 0, or +1
Subtract(NUMTYPE)
SUMMARY

Subtract of NewType(x) and NewType(y)

PARAMETERS
rhs
NUMTYPE
Right-hand side of the operation
DECLARATION
[Pure]
public virtual NUMTYPE Subtract(NUMTYPE rhs)
RETURNS
NUMTYPE
lhs - rhs
Sum()
SUMMARY

Sum

DECLARATION
public virtual A Sum()
RETURNS
A
ToString()
SUMMARY

Generate a text representation of the NumType and value

DECLARATION
[Pure]
public override string ToString()
RETURNS
string