feat(List)
This commit is contained in:
34
src/utils/concept.js
Normal file
34
src/utils/concept.js
Normal file
@ -0,0 +1,34 @@
|
||||
export function satisfiesConcept(obj, pure_virtual, virtual, debug) {
|
||||
if (typeof obj !== 'object' || obj === null) {
|
||||
return false;
|
||||
}
|
||||
if (debug) {
|
||||
const missingMethods = []
|
||||
|
||||
pure_virtual.forEach((method) => {
|
||||
if (typeof obj[method] !== 'function') {
|
||||
missingMethods.push(method)
|
||||
}
|
||||
})
|
||||
|
||||
virtual.forEach((method) => {
|
||||
if (!(method in obj)) {
|
||||
missingMethods.push(method)
|
||||
}
|
||||
})
|
||||
|
||||
if (missingMethods.length !== 0) {
|
||||
console.debug(obj.constructor.name, missingMethods)
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if (!pure_virtual.every((method) => typeof obj[method] === 'function')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!virtual.every((method) => method in obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user