const isObjectOfType = typeName => a =>
({}).toString.call(a) === `[object ${typeName}]`;
// isList :: * -> Boolean
export const isList = isObjectOfType('Array');
// isObject:: * -> Boolean[object
export const isObject = isObjectOfType('Object');
// match :: EnumTagType -> Pattern -> b
export const match = (instance, pattern) => {
if (!instance || !instance.name) throw new Error('Invalid instance passed');
const action = pattern[instance.name] || pattern._;
if(!action) throw new Error('Non-Exhaustive pattern. You must pass fallback case `_` in the pattern');
return action(...instance.args);
};
// listToObject :: (a -> String, a -> b, [a]) -> Object b
export const listToObject = (toKey, toValue, list) =>
list.reduce((obj, item) => ({ ...obj, [toKey(item)]: toValue(item) }), {});
export const isConstructor = constructors => t => constructors.indexOf(t) !== -1 || constructors.indexOf(t.name) !== -1
|