Skip to content
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

462 - Currying 2 #6311

Open
okayu29 opened this issue Feb 7, 2022 · 0 comments
Open

462 - Currying 2 #6311

okayu29 opened this issue Feb 7, 2022 · 0 comments
Labels
462 answer Share answers/solutions to a question en in English

Comments

@okayu29
Copy link

okayu29 commented Feb 7, 2022

type Drop<N, T extends any[], A extends any[] = []>
     = A['length'] extends N ? T 
     : T extends [infer L, ...infer R] ? Drop<N, R, [[], ...A]> : []

type PrefixUnion<T> = T extends [...infer L, infer R] ? T | PrefixUnion<L> : never

type DPC<Args extends any[], Ret>
    = Args['length'] extends 0 ? Ret extends true ? boolean : Ret
    : <T extends PrefixUnion<Args>>(...x: T) => DPC<Drop<T['length'], Args>, Ret> 

declare function DynamicParamsCurrying<F>(fn: F): F extends (...x: infer A) => infer R ? DPC<A, R> : never
@okayu29 okayu29 added answer Share answers/solutions to a question en in English labels Feb 7, 2022
@github-actions github-actions bot added the 462 label Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
462 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

1 participant