NewType<NEWTYPE, A, PRED> Class

NewType - inspired by Haskell's 'newtype' keyword. https://wiki.haskell.org/Newtype Derive type from this one to get: Equatable, Comparable, Appendable, Subtractable, Multiplicable, Divisible, Foldable, Monadic, Functor, Interable: strongly typed values.

For example:

class Metres : NewType<Metres, double> { public Metres(double x) : base(x) {} }
class Hours : NewType<Hours, double> { public Hours(double x) : base(x) {} }


Will not accept null values

DECLARATION
[Serializable]
public abstract class NewType<NEWTYPE, A, PRED> : IEquatable<NEWTYPE>,
IComparable<NEWTYPE>
NAMESPACE
LanguageExt

Constructors

NewType(A)
SUMMARY

Constructor

PARAMETERS
value
A
Value to bind
DECLARATION
public ctor NewType(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, NEWTYPE> New
Value
DECLARATION
public readonly A Value

Methods

Bind(Func<A, NEWTYPE>)
SUMMARY

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

PARAMETERS
bind
Func<A, NEWTYPE>
Bind function
DECLARATION
[Pure]
public virtual NEWTYPE Bind(Func<A, NEWTYPE> bind)
RETURNS
NEWTYPE
CompareTo(NEWTYPE)
PARAMETERS
other
NEWTYPE
DECLARATION
[Pure]
public virtual int CompareTo(NEWTYPE other)
RETURNS
int
Equals(NEWTYPE)
PARAMETERS
other
NEWTYPE
DECLARATION
[Pure]
public virtual bool Equals(NEWTYPE other)
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 NewType (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 NewType 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 NewType bound value
ForAll(Func<A, bool>)
SUMMARY

Run a predicate for all values in the NewType (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 NEWTYPE Map(Func<A, A> map)
RETURNS
NEWTYPE
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 NEWTYPE Select(Func<A, A> map)
RETURNS
NEWTYPE
SelectMany(Func<A, NewType<NEWTYPE, 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, NewType<NEWTYPE, A, PRED>>
Bind function
project
Func<A, A, A>
Final projection (select)
DECLARATION
[Pure]
public virtual NEWTYPE SelectMany(Func<A, NewType<NEWTYPE, A, PRED>> bind, Func<A, A, A> project)
RETURNS
NEWTYPE
ToString()
SUMMARY

Generate a text representation of the NewType and value

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