I'm trying to implement a function that would obey the following interface in TypeScript 3.2:
const s: string = chain(
() => 123,
(n: number) => "abc"
(s: string) => s
);
I'm able to do so by declaring multiple-arity functions:
function chain2<A, B>(a: () => A, b: (a: A) => B): B {
return b(a());
}
function chain3<A, B, C>(a: () => A, b: (a: A) => B, c: (b: B) => C): C {
return c(b(a()));
}
// and so on
However, since the release of Tuples in rest parameters and spread expressions, I was wondering if there would be a way to do so with only one function declaration. I've been trying different approaches with no success so far.