Skip to content

Conversation

Destaby
Copy link

@Destaby Destaby commented Dec 16, 2019

No description provided.

callback(new Error('obj needed'));
return;
}
for (const key in obj) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will iterate all object keys plus inherited keys from prototype chain.

const contract = (fn, ...types) => null;
const contract = (fn, ...types) => (...arr) => {
for (let i = 1; i < types.length - 1; i++) {
if (typeof fn(...arr) !== types[i].name.toLowerCase()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use intermediate variables

throw new TypeError('Types are different');
}
}
return fn(...arr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check result type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Last argument is a result type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check result type after calling fn

@tshemsedinov
Copy link
Member

Please rebase on master to activate CI

@Destaby Destaby changed the title My work My work is redone Dec 16, 2019
throw new TypeError('Types are different');
}
}
return fn(...arr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check result type after calling fn

if (argType !== neededArgType) {
throw new TypeError('Types are different');
}
if (resultType !== neededReType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you check result types in loop?

@Destaby Destaby changed the title My work is redone My work Dec 17, 2019
@Destaby
Copy link
Author

Destaby commented Dec 17, 2019 via email

@tshemsedinov
Copy link
Member

Please don't send changes in email, commit it directly to git because I need to see diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants