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    3x 26x     48x 26x 3x   23x               2x     23x   23x        
 
// type EnumAction = ...a -> EnumTagType
const checkType = (props, args) =>
    !props? true : props.length === args.length;
 
// EnumTag :: (String, EnumType, ?Array String) -> ...a -> EnumTagType
export const EnumTag = (name, Type, props) => (...args) => {
    if(!checkType(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 | EnumToken ~> Boolean
        is: otherType => [otherType, otherType.name].indexOf(name) !== -1,
    };
 
    self.match = pattern => Type.match(self, pattern);
 
    return self;
};
 
export default EnumTag;