josdejong / josdejong/typed-function
Set length property on typed functions
- Dominant language
- JavaScript
- Stars
- 79
- Forks
- 22
- PR merge metrics
- No merged PRs in 30d
Description
_Note: This is related to #154, but I think smaller in scope and could be handled separately if this is decided to be a good idea._
I've noticed that all typed functions have length 2. For example:
```ts
const f = math.evaluate('f(w,x,y,z) = w*x*y*z')
console.log(f.length) // 2
```
whereas I would expect `f.length` to be 4.
**Suggestion:**
- if a typed function has only one signature, its length should be the length of that signature.
- **alternatively** the length of a typed function should be the length of its first signature.
**Notes:**
- #154 seems very useful, but I think that having a reasonable length property would also be useful. It would make typed functions behave more like "normal" js functions. Additionally, there's less (imo) of a design issue here since the API would be much simpler.
- My *particular* motivation is to supply a random sample to the result of `math.evaluate` so I can tell if evaluating the function would result in an error. For example, `const f = math.evaluate(f(x) = 2^[1,2,3])` evaluates fine. but calling `f(anything)` will throw an error. For this purple, having a valid sample in f's domain isn't really necessary (evaluating to NaN would be fine) but I do need to know how many params it has.
My current workaround is getting the number of params from the FunctionAssignmentNode, but I'd prefer to implement the "sample evaluation of f" logic in a way that is agnostic as to whether `f` is coming from MathJs or from some other source.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.