Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/gabrielelana/type-level-game-of-life

Type Level Game of Life in TypeScript
https://github.com/gabrielelana/type-level-game-of-life

Last synced: about 1 month ago
JSON representation

Type Level Game of Life in TypeScript

Awesome Lists containing this project

README

        

# Type Level Game of Life in TypeScript

Not a line of JavaScript will be generated by compiling the code in `gol.ts`
everything that happens it happens at compile time.

The goal was to implement the [Game of
Life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) using only
TypeScript type checker.

What it means is that all the calculations needed to do the simulation are done
by creating types from other types until we have a type (`EvolveU`) that
transform a type that represents a universe (grid of cells) into a type that
represents the evolved universe.

You can find some of the capabilities used in the following pages of TypeScript
official documentation:

- [Generics](https://www.typescriptlang.org/docs/handbook/2/generics.html)
- [Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html)
- [Template Literal Types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html)

This exercise is not meant to be of any use if not to explore what you can do
and learn techniques that can be used in real life situations.

If you don't have time to setup a local development environment here's a
[Playground](https://www.typescriptlang.org/play?#code/C4TwDgpgBAogigHgBoBooE0B8UC8UAUCAKpvgJS7ZFQQAewEAdgCYDOUSUA-FAIxQAuKACYKdBi3bFSFHFRr0mbDACgo3PmsEitPYACcArhC1CAZgEMANqwgBuFStCQoRQ2CsRkaLLigBtVAwAXQcncGgAZQB3CzA3Dy9qcSV2fwtGEDQMkGDsPGTFSQCAS0YzCH0ONDKKqvRg3QD0NCRG9SFGCAA3SrCAen6OPxhaSABjBmYVQYw-AHES3sZwl3gibwx813dPBBbYRCCsTDDnaABBVlt9YGQFCWUDYygAHx3EhBy0Z4hMbc4KWKvyaII6wyBygSe1qlQw2UymCa6FMUC6vX0ZwiUAAcgB7O6AorKABGeLxngybw+e2+UDJFIgGX+fiJj3YYI0lhsJnBbNSUG5tlBRl52n5xWhXlh9Rq5ThAH0AFpI9Q8dAPAWctU0rwHIV-LTgq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KYrXLjooBEqnpyI0reg0AMrKhsrcrkqQB2B8rhtZwYBugKRyK18lLdt5sGLSqroBZaKXL0K3LHK994suyprYr4rHLghJFaK1tATqQ8SmgNrVLQLFrlLpq4rZriLgA1qzDZL5tAoq9OK9r5tUQrqrAck9VbKE5rYnq0A+qBqvB7rIEM4qTXqi9Xj5TPrYB+rWJfrgqJqB5uTJMgbbT3qNg-qvqIbyKUaO9AbhN+TkbobrrwafqEAMakorSwogaZMDTvIwbvrIaia8bIFxJSbs4gaXjKaPrxr8aab0b6bJTKTyogaISQag5qa0aoaRrIFEImaFQgasShaqaObIEuaxapKYaP0pagbaS5b2bhtNqCbaaMbSN1beScbCsdaYalbTbNt8aAb+bXJZS7KNgRbCawbHYsbeB9SHbLbdaLawbR83bEaa5cbxbUbnaFabr3wjbeAe82bHaw69byKwbGa3aKbPanbabE6dSHJXreBWbU646fa47Ja3bBaY6vbzbRay78a1a3bZbS606E786KMBs1hRbHMgzM9Ws9cBZRLlBxKTC5KkyBZ4CWKpZJxmL5Y+7Hs-ApFwyajoz5iww1q8BQC5DLIIDTzYDMCoBkyGtAtVCBZPcxK+FqLBFsZlq3LbynS0zXBJFOLuKGZeK-5HMBKhK+LHMNEmhn7kY1tizt6e72BJ65K1LQ0J7j6BFHtVyNAla27Bz36DF58nZ-BysQ7abn7lTNKnLvw1Y1D9KY1zLKhmz8GGxE0iGtCrLvY0pXITb09hAUHegYHsLeApbKGPaka+tGG6GIAGHPLhBy4gA)
for you to play with.

To see representation of the types bring the pointer over the name of the type
or the type expression. In the example there are two universes represented:
`UniverseS1` and `UniverseS2`, by following the Game of Life rules they form a
periodic pattern, `UniverseS2` is the next evolution step of `UniverseS1` and
`UniverseS1` is the next evolution step of `UniverseS2`. You can see the those
two final tests at the end of the file as `type _10001` and `type _10002`.