4 ms·
> The implementation isn't even that horrible You're making me blush! The list of integers could be replaced by using tuples and reading their lengths to do b
by phpnode 6y ago
> The implementation isn't even that horrible
You're making me blush!
The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic. Might run into recursion limits though.
- jedimastert 6y ago> The list of integers could be replaced by using tuples and reading their lengths to do basic arithmetic. Is that anything like church encoding? https://www.wikiwand.com/en/Church_encoding#/Church_numerals https://www.wikiwand.com/en/Church_encoding#/Church_numerals
- jitl 6y agoNot really. In the Typescript type system tuple types are array types where the length is encoded in the type system. Tuple types can be “added” by concatenation to produce a new tuple type: type two = [0, 0] type three = [0, 0, 0] type five = [...two, ...three] type TupleToNumber<T extends any[]> = T[“length”] const num: TupleToNumber<five> = 5
- akavi 6y agoAm I understanding this correctly that typescript provides a type-level property on tuples called `"length"`?