All files EnumTag.js

100% Statements 11/11
100% Branches 4/4
100% Functions 5/5
100% Lines 9/9
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 31 32 33          3x 26x       48x 26x 3x   23x               2x       23x   23x        
 
// type TypeConstructor = ...a -> EnumTagType
 
 
// validateArguments :: (?Array String, [a]) -> Boolean
const validateArguments = (props, args) =>
    !props? true : props.length === args.length;
 
// (constructor)
// EnumTag :: (String, EnumType, ?Array String) -> TypeConstructor
export const EnumTag = (name, Type, props) => (...args) => {
    if(!validateArguments(props, args))
        throw new TypeError(`Invalid number of arguments 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
    self.match = pattern => Type.match(self, pattern);
 
    return self;
};
 
export default EnumTag;