For many cases, including #38, changing argument order is extremely useful, and this function is not so hard to implement if we consider only basic cases.
type FlipResult<F extends (a: never) => (b: never) => any> = F extends (a: infer A) => infer BR ? (
BR extends (b: infer B) => infer R ?
Fun<[B], Fun<[A], R>> :
never
) :
never;
function flip<F extends Fun<[never], Fun<[never], any>>(f: F): FlipResult<F> {
return function (b) {
return function (a) {
return f(a)(b);
};
};
}
Description
For many cases, including #38, changing argument order is extremely useful, and this function is not so hard to implement if we consider only basic cases.