From 32a8cedd1e7e1b69e3900c12ba6d2d074d408092 Mon Sep 17 00:00:00 2001 From: Michael Bock Date: Tue, 25 May 2021 19:12:25 +0200 Subject: [PATCH] Cleanup --- .github/workflows/build.yml | 2 ++ README.md | 22 +++++------- examples/index.ts | 3 ++ package.json | 6 +++- yarn.lock | 68 +++++++++++++++++++++++++++++++++++++ 5 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 examples/index.ts diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2b69666..44dd73b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,6 +22,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: yarn install - run: yarn run build + - run: yarn run example - run: yarn test deploy-docs: @@ -34,6 +35,7 @@ jobs: run: | yarn install yarn run build + yarn run example yarn test yarn docs diff --git a/README.md b/README.md index 7a959d6..7c90228 100644 --- a/README.md +++ b/README.md @@ -7,16 +7,14 @@ - [Install](#install) -- [Example](#example) +- [Examples](#examples) - [Imports](#imports) - [Construction](#construction) - [Operations on vectors](#operations-on-vectors) - [Lookups](#lookups) - - [Vec 2](#vec-2) - - [Vec 3](#vec-3) - - [Vec 5](#vec-5) + - [Vectors of anything](#vectors-of-anything) - [Vector math](#vector-math) -- [Limitation](#limitation) +- [Limitations](#limitations) - [TODO (PR's welcome)](#todo-prs-welcome) @@ -32,7 +30,7 @@ or npm install fp-ts fp-ts-sized-vectors ``` -## Example +## Examples ### Imports @@ -97,13 +95,13 @@ assert.deepStrictEqual(vecAB, [10, 20, 30, 40, 50]) ### Lookups -The fact that the vectors carry their lengths as typelevel information gives us many useful compile time guarantees. +The fact that the vectors carry their lengths as type level information gives us many useful compile time guarantees. Below you can see that we receive a `number` for _in range_ indices and something of type `unknown` for _out of bounds_ indices. That works because we specify the indices as number literals. We do not receive any union types like `number | undefined` or `Option`. That's one of the main advantages over the `Array` type. -#### Vec 2 +Vec 2 @@ -115,7 +113,7 @@ const a_2: unknown = V.lookup(2)(vecA) -#### Vec 3 +Vec 3 @@ -128,7 +126,7 @@ const b_3: unknown = V.lookup(3)(vecB) -#### Vec 5 +Vec 5 @@ -145,7 +143,7 @@ const ab_5: unknown = V.lookup(5)(vecAB) ### Vectors of anything -The size of vectors are caputured as typelevel numbers, their inner value can be of arbitrary types. In the above example we used the `number` type as that's quite common. But we could also just define a vector of strings: +The size of vectors are captured as type level numbers, their inner value can be of arbitrary types. In the above example we used the `number` type as that's quite common. But we could also just define a vector of strings: @@ -175,8 +173,6 @@ const vecR: Vec<3, number> = pipe( assert.deepStrictEqual(vecR, [2.1, 4.2, 6.3]) ``` -The above calculation only compiles if all vectors are of the same length. This is another situation where we profit from the type level lengths. - ## Limitations diff --git a/examples/index.ts b/examples/index.ts new file mode 100644 index 0000000..e2b0858 --- /dev/null +++ b/examples/index.ts @@ -0,0 +1,3 @@ +import * as One from './one' + +One diff --git a/package.json b/package.json index 4f7e404..af0e801 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,8 @@ "prettier": "^2.2.1", "prettier-plugin-jsdoc": "^0.3.13", "ts-jest": "^26.5.3", + "ts-node": "^10.0.0", + "tsconfig-paths": "^3.9.0", "typescript": "^4.2.3" }, "scripts": { @@ -33,6 +35,8 @@ "md": "yarn markdown --config ./markdown.config.js", "md:watch": "while inotifywait -e close_write README.md; do yarn md; done", "docs-preview:watch": "cd docs; bundle exec jekyll serve --livereload", - "docs-preview": "cd docs; bundle exec jekyll serve" + "docs-preview": "cd docs; bundle exec jekyll serve", + "ts-node_": "ts-node -r tsconfig-paths/register", + "example": "yarn ts-node_ examples" } } diff --git a/yarn.lock b/yarn.lock index 8fba263..1a1e627 100644 --- a/yarn.lock +++ b/yarn.lock @@ -541,6 +541,26 @@ multimatch "^5.0.0" typescript "~4.1.3" +"@tsconfig/node10@^1.0.7": + version "1.0.7" + resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.7.tgz#1eb1de36c73478a2479cc661ef5af1c16d86d606" + integrity sha512-aBvUmXLQbayM4w3A8TrjwrXs4DZ8iduJnuJLLRGdkWlyakCf1q6uHZJBzXoRA/huAEknG5tcUyQxN3A+In5euQ== + +"@tsconfig/node12@^1.0.7": + version "1.0.7" + resolved "https://registry.yarnpkg.com/@tsconfig/node12/-/node12-1.0.7.tgz#677bd9117e8164dc319987dd6ff5fc1ba6fbf18b" + integrity sha512-dgasobK/Y0wVMswcipr3k0HpevxFJLijN03A8mYfEPvWvOs14v0ZlYTR4kIgMx8g4+fTyTFv8/jLCIfRqLDJ4A== + +"@tsconfig/node14@^1.0.0": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@tsconfig/node14/-/node14-1.0.0.tgz#5bd046e508b1ee90bc091766758838741fdefd6e" + integrity sha512-RKkL8eTdPv6t5EHgFKIVQgsDapugbuOptNd9OOunN/HAkzmmTnZELx1kNCK0rSdUYGmiFMM3rRQMAWiyp023LQ== + +"@tsconfig/node16@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@tsconfig/node16/-/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1" + integrity sha512-FTgBI767POY/lKNDNbIzgAX6miIDBs6NTCbdlDb8TrWovHsSvaVIZDlTqym29C6UqhzwcJx4CYr+AlrMywA0cA== + "@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7": version "7.1.12" resolved "https://registry.yarnpkg.com/@types/babel__core/-/babel__core-7.1.12.tgz#4d8e9e51eb265552a7e4f1ff2219ab6133bdfb2d" @@ -608,6 +628,11 @@ jest-diff "^26.0.0" pretty-format "^26.0.0" +"@types/json5@^0.0.29": + version "0.0.29" + resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" + integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= + "@types/minimatch@^3.0.3": version "3.0.3" resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" @@ -1228,6 +1253,11 @@ core-util-is@1.0.2, core-util-is@~1.0.0: resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" integrity sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= +create-require@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/create-require/-/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333" + integrity sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ== + cross-spawn@^6.0.0: version "6.0.5" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-6.0.5.tgz#4a5ec7c64dfae22c3a14124dbacdee846d80cbc4" @@ -2724,6 +2754,13 @@ json5@2.x, json5@^2.1.2: dependencies: minimist "^1.2.5" +json5@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe" + integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow== + dependencies: + minimist "^1.2.0" + jsonfile@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" @@ -3929,6 +3966,11 @@ strip-ansi@^6.0.0: dependencies: ansi-regex "^5.0.0" +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + integrity sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM= + strip-bom@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-4.0.0.tgz#9c3505c1db45bcedca3d9cf7a16f5c5aa3901878" @@ -4123,6 +4165,22 @@ ts-morph@^9.1.0: "@ts-morph/common" "~0.7.0" code-block-writer "^10.1.1" +ts-node@^10.0.0: + version "10.0.0" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be" + integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg== + dependencies: + "@tsconfig/node10" "^1.0.7" + "@tsconfig/node12" "^1.0.7" + "@tsconfig/node14" "^1.0.0" + "@tsconfig/node16" "^1.0.1" + arg "^4.1.0" + create-require "^1.1.0" + diff "^4.0.1" + make-error "^1.1.1" + source-map-support "^0.5.17" + yn "3.1.1" + ts-node@^8.10.2: version "8.10.2" resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-8.10.2.tgz#eee03764633b1234ddd37f8db9ec10b75ec7fb8d" @@ -4134,6 +4192,16 @@ ts-node@^8.10.2: source-map-support "^0.5.17" yn "3.1.1" +tsconfig-paths@^3.9.0: + version "3.9.0" + resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.9.0.tgz#098547a6c4448807e8fcb8eae081064ee9a3c90b" + integrity sha512-dRcuzokWhajtZWkQsDVKbWyY+jgcLC5sqJhg2PSgf4ZkH2aHPvaOY8YWGhmjb68b5qqTfasSsDO9k7RUiEmZAw== + dependencies: + "@types/json5" "^0.0.29" + json5 "^1.0.1" + minimist "^1.2.0" + strip-bom "^3.0.0" + tunnel-agent@^0.6.0: version "0.6.0" resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd"