All files Enum.js

100% Statements 8/8
100% Branches 4/4
100% Functions 4/4
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30            51x 32x 3x   29x               2x   6x   29x              
import { createEnumFactory } from './utils';
import T, { validateArgs } from './Type';
 
// type TypeConstructor = ...a -> EnumTagType
 
// createConstructor :: (Enum, ConstructorDescription) -> TypeConstructor
export const createConstructor = (Type, { name, props }) => (...args) => {
    if(props ? !validateArgs(props, args) : false)
        throw new TypeError(`Invalid number of args passed to constructor ${name}`);
 
    const self = {
        // args :: Array *
        args,
        // name :: String
        name,
        // props :: ?Array String
        props,
        // is :: String | EnumTagType | ConstructorDescription ~> Boolean
        is: otherType => [otherType, otherType.name].indexOf(name) !== -1,
        // match :: Object (* -> b) ~> b
        match: pattern => Type.match(self, pattern),
    };
    return self;
};
 
// Enum :: Array String | Object * -> Enum
export default createEnumFactory({ createConstructor });
 
// Type
export { T };