Module: type

Methods

(static) dataType(a) → {function}

Return the data type of a given object. In JavaScript, this is simply the object's constructor, so this function essentially serves as an alias for terminological clarification.

Parameters:
Name Type Description
a *

Any object

Source:
Returns:

The object's constructor function

Type
function
Example
dataType(0);             // function Number() { [native code] }
const lst = list(1,2,3);
dataType(lst);           // => function List(head, tail) { ... }
lst.typeOf();            // => List // more useful if you don't need a function pointer

(static) defines(…methods) → {function}

Return a closure that checks whether a given object is a member of a predefined type class. Note that the library only checks for the existence of the required property or properties. Whether or not those properties are functions and whether or not they return the values expected by the type class are not verified. This is a utility function for defining new type classes.

Parameters:
Name Type Attributes Description
methods string <repeatable>

A comma separated list of functions that a data type must define in order to be a member of the type class defined by this function

Source:
Returns:

A closure that returns true if a given object implements all the specified methods, false otherwise

Type
function
Example
// require that instances of the `Eq` type class define an `isEq` function:
const Eq = defines(`isEq`);

// require that instances of `Traversable` define `traverse` and are also instances of `Functor`
// and `Foldable`:
const Traversable = defines(`fmap`, `foldr`, `traverse`);

(static) type(a) → {string}

Return the type of any object as specified by this library or, otherwise, its primitive type.

Parameters:
Name Type Description
a *

Any object

Source:
Returns:

The type of the object

Type
string
Example
type(0);              // => number
const t = tuple(1,2);
type(t);              // => (number,number)

(static) typeCheck(a, b) → {boolean}

Determine whether two objects are the same type. Return true if they are and false otherwise.

Parameters:
Name Type Description
a *

Any object

b *

Any object

Source:
Returns:

true if the two objects are the same type, false otherwise

Type
boolean
Example
typeCheck(0, 1);   // => true
typeCheck(0, `a`); // => false