stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

RFC: add assertion utility to test if a value is "callable"

Open kgryte opened this issue 6 years ago • 2 comments

Checklist

Please ensure the following tasks are completed before filing an issue.

  • [x] Read and understood the Code of Conduct.
  • [x] Searched for existing issues and pull requests.
  • [x] If this is a general question, searched the FAQ for an existing answer.
  • [x] If this is a feature request, the issue name begins with RFC:.

Description

Description of the issue (or feature request).

This RFC proposes adding an assertion utility to test whether a value is callable. A value is callable if the value is a function, generator, or an ES6 class.

Prior art:

Package: @stdlib/assert/is-callable Alias: isCallable

Related Issues

Does this issue (or feature request) have any related issues?

No.

Questions

Any questions for reviewers?

No.

Other

Any other information relevant to this issue (or feature request)? This may include screenshots, references, stack traces, sample output, and/or implementation notes.

No.

kgryte avatar Apr 19 '18 13:04 kgryte

@kgryte Doesn't isFunction serve the purpose of this package perfectly fine? In what circumstances would the behavior differ?

Planeshifter avatar Aug 13 '21 14:08 Planeshifter

I believe isCallable is intended to be more generic (see here). For practical purposes in the project, isFunction should suffice for input validation. However, for checking for other function flavors, we may want a looser check to filter out non-callable objects before more specific checks. In general, an object is "callable" if it has a [[call]] slot. This extends beyond normal functions, I believe.

kgryte avatar Aug 13 '21 17:08 kgryte