-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing type of reduce
with initial seed in declarative form
#239
Comments
Thank you for your interest :) I think it could be a better expression This is something we discussed previously regarding and it would be difficult to change the existing interface because of existing users😭 |
It turns out that there is no way to support both seed and high order reduce in a single function signature. TerminologyLet's define some terminology for this issue.
PossibilitiesWe'd like to support following 6 cases of
3 parameter cases don't matter because they're disjoint and support all possible ways of having seed. 1 parameter case is just unique so let's ignore them. The major problem is solving confusing cases which have 2 parameters.
Our goal is making TypeScript distinguish these three cases. AmbiguityComplete logic of type inference is not well known (and I don't know either), but one thing is sure: It's imperfect and kind of greedy (I think backtracking may cause exponential inference time). As my guess, following seems to be true.
So let's discard the first explicit case. Now we assume that user may give imperfect partial type information via parameters. Theorem 1
Since Theorem 2
When
|
Any further discussion? I think adding |
@Phryxia Sorry for the late reply. I also studied what you wrote. By adding the necessary expressions without breaking the existing usage, |
Thank you for your response. I'll work this on this weekend. |
* refactor: extract type of function arg in `reduce` * feat: implement `reduceLazy` (#239) * docs: add jsdoc for `reduceLazy` --------- Co-authored-by: Phryxia <xahhaepica@gmail.com>
It's released 🎉 |
Bug Report
Consider following scenario.
Currently, with FxTS, it can be done with following pipeline
But actually, I tried with following approach at first, which has type failure.
Interestingly this works if I bypass type check. And it seems to be natural to do so, similar to other FxTS APIs.I think I was wrong at that time for some unknown reasons. It is not supported in current version. (added on 2024-02-17)🙁 Actual behavior
There is no such type signature for declarative form of
reduce
withseed
in the type definition.🙂 Expected behavior
Maybe, this might work. If you consider this is valid, tell me so I'll raise for pull request.
Version Information
The text was updated successfully, but these errors were encountered: