Skip to content

Instantly share code, notes, and snippets.

@henix
henix / tuples.ts
Created March 18, 2020 11:32 — forked from hmil/tuples.ts
Well-typed variable-length tuples in TypeScript
/**
* Arbitrary-length tuples
* =======================
*
* Working with tuples of unknown length in TypeScript is a pain. Most library authors fall back on enumerating all possible
* tuple lengths up to a threshold (see an example here https://github.com/pelotom/runtypes/blob/fe19290d375c8818d2c52243ddc2911c8369db37/src/types/tuple.ts )
*
* In this gist, I'm attempting to leverage recursion to provide support for arbitrary length tuples. This has the potential
* to make some kinds of declarative APIs nicer and enhance type inference in some cases.
* This example shows how to take a variable-length tuple as an input, transform each of its types and use the resulting
@henix
henix / fcicq-question.txt
Created February 27, 2018 10:55 — forked from fcicq/fcicq-question.txt
A simple question
有一存有整数的数组 A[n] (n <= 2^31 - 1, 但需要的话可以再扩大), 其中 0 <= i, A[i] <= n-1 且 i!=j 时 A[i]!=A[j] (即一个排列). 用你认为*最高效*的方法求 B=A^(-1) (即对范围内满足 A[B[i]]=i 的 B)
/*************
* colors.js *
*************
*
* You're almost at the exit. You just need to get past this
* color lock.
*
* Changing your environment is no longer enough. You must
* learn to change yourself. I've sent you a little something
* that should help with that.