Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add const type parameters on patterns constructor #63

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,18 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn
- run: yarn build
node-version: lts/*
cache: yarn

- run: yarn install --pure-lockfile
- run: yarn typecheck
- run: yarn test
- run: yarn build

- name: Build docs
run: cd docs && yarn && yarn build
Expand Down
20 changes: 9 additions & 11 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,18 @@ jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
registry-url: "https://registry.npmjs.org"
- run: yarn
- run: yarn build
node-version: lts/*
cache: yarn

- run: yarn install --pure-lockfile
- run: yarn typecheck
- run: yarn test
- run: yarn build

- name: Publish
run: yarn publish
Expand Down
19 changes: 11 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
"registry": "https://registry.npmjs.org"
},
"prettier": {
"trailingComma": "all"
"trailingComma": "all",
"plugins": [
"prettier-plugin-organize-imports"
]
},
"scripts": {
"build": "yarn clean && microbundle -f cjs,es",
Expand All @@ -41,14 +44,14 @@
"benchmark": "node benchmark/src/option && node benchmark/src/result && node benchmark/src/future"
},
"devDependencies": {
"@types/benchmark": "^2.1.2",
"@types/benchmark": "^2.1.5",
"benchmark": "^2.1.4",
"fp-ts": "^2.15.0",
"fp-ts": "^2.16.1",
"microbundle": "^0.15.1",
"prettier": "^2.8.8",
"prettier-plugin-organize-imports": "^3.2.2",
"ts-pattern": "^4.3.0",
"typescript": "^5.1.6",
"vitest": "^0.31.0"
"prettier": "^3.1.0",
"prettier-plugin-organize-imports": "^3.2.4",
"ts-pattern": "^5.0.6",
"typescript": "^5.3.2",
"vitest": "^1.0.1"
}
}
7 changes: 3 additions & 4 deletions src/AsyncData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ const asyncDataProto = (<A>(): IAsyncData<A> => ({
return this.tag === "Done"
? config.Done(this.value)
: this.tag === "Loading"
? config.Loading()
: config.NotAsked();
? config.Loading()
: config.NotAsked();
},

tap(this: AsyncData<A>, func: (asyncData: AsyncData<A>) => unknown) {
Expand Down Expand Up @@ -342,7 +342,7 @@ const Loading = <A = never>(): AsyncData<A> => LOADING as Loading<A>;
const NotAsked = <A = never>(): AsyncData<A> => NOT_ASKED as NotAsked<A>;

const asyncDataPattern = {
Done: <A>(value: A) => ({ tag: "Done", value } as const),
Done: <const A>(value: A) => ({ tag: "Done", value }) as const,
NotAsked: { tag: "NotAsked" } as const,
Loading: { tag: "Loading" } as const,
};
Expand Down Expand Up @@ -422,5 +422,4 @@ export const AsyncData = {
Object.prototype.isPrototypeOf.call(asyncDataProto, value)),

P: asyncDataPattern,
pattern: asyncDataPattern,
};
8 changes: 3 additions & 5 deletions src/OptionResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const NONE = (() => {
const None = <A = never>(): Option<A> => NONE as None<A>;

const optionPattern = {
Some: <A>(value: A) => ({ tag: "Some", value } as const),
Some: <const A>(value: A) => ({ tag: "Some", value }) as const,
None: { tag: "None" } as const,
};

Expand Down Expand Up @@ -253,7 +253,6 @@ export const Option = {
},

P: optionPattern,
pattern: optionPattern,
};

interface IResult<A, E> {
Expand Down Expand Up @@ -466,8 +465,8 @@ const Error = <A = never, E = never>(value: E): Result<A, E> => {
};

const resultPattern = {
Ok: <A>(value: A) => ({ tag: "Ok", value } as const),
Error: <E>(value: E) => ({ tag: "Error", value } as const),
Ok: <const A>(value: A) => ({ tag: "Ok", value }) as const,
Error: <const E>(value: E) => ({ tag: "Error", value }) as const,
};

export const Result = {
Expand Down Expand Up @@ -592,5 +591,4 @@ export const Result = {
},

P: resultPattern,
pattern: resultPattern,
};
4 changes: 2 additions & 2 deletions src/Serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const decode = (value: string) => {
return value.tag === "NotAsked"
? AsyncData.NotAsked()
: value.tag === "Loading"
? AsyncData.Loading()
: AsyncData.Done(value.value);
? AsyncData.Loading()
: AsyncData.Done(value.value);
}
return value;
});
Expand Down
Loading