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

Dancrumb/issue195 #199

Merged
merged 3 commits into from
May 5, 2024
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
44 changes: 0 additions & 44 deletions .eslintrc.js

This file was deleted.

109 changes: 8 additions & 101 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
51 changes: 51 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import tsEslint from '@typescript-eslint/eslint-plugin'
import tsParse from '@typescript-eslint/parser'

export default [
{
files: ["**/*.ts"],
},{
ignores: [
'.pnp.*',
'**/dist/**',
'**/coverage/**',
'**/node_modules/**',
'**/docs/**'
]
},
{
languageOptions: {
ecmaVersion: 2019,
sourceType: 'module',
parser: tsParse
},
plugins: { '@typescript-eslint': tsEslint }
}, {
rules: {
'@typescript-eslint/adjacent-overload-signatures': 'error',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-misused-new': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/no-shadow': ['error'],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
],
'@typescript-eslint/no-redeclare': 'error',
'no-dupe-class-members': 'off',
'@typescript-eslint/no-dupe-class-members': 'error',
eqeqeq: ['error', 'smart'],
'no-caller': 'error',
'no-invalid-this': 'error',
'no-new-wrappers': 'error',
'no-shadow': 'off',
'no-throw-literal': 'error',
'no-unused-labels': 'error',
'no-var': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
'no-redeclare': 'off'
},
}];
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"scripts": {
"build": "yarn run tsc -p tsconfig.production.json",
"prerelease": "yarn run prepare",
"lint": "yarn run eslint -c .eslintrc.js --ext .ts src",
"lint:ci": "yarn run eslint -c .eslintrc.js --ext .ts --format junit --output-file ./reports/eslint.xml src",
"lint": "yarn run eslint",
"lint:ci": "yarn run eslint --format junit --output-file ./reports/eslint.xml src",
"postversion": "git push && git push --tags",
"prettier:cli": "yarn run prettier \"src/**/*.ts\"",
"prettier:check": "yarn run prettier:cli -- -l",
Expand All @@ -30,13 +30,13 @@
"license": "MIT",
"repository": "github:dancrumb/fpish",
"devDependencies": {
"@eslint/js": "^9.2.0",
"@types/node": "^20.12.8",
"@typescript-eslint/eslint-plugin": "7.8.0",
"@typescript-eslint/parser": "7.8.0",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "9.2.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.1.3",
"eslint-formatter-junit": "^8.40.0",
"git-cz": "4.9.0",
"prettier": "3.2.5",
"ts-node": "10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion src/AsyncData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('AsyncData', () => {
});
test('handles loading data', () => {
const data = AsyncData.loading<number>();
expect(data.filter((x) => true).isLoading()).toBe(true);
expect(data.filter(() => true).isLoading()).toBe(true);
});
});

Expand Down
13 changes: 13 additions & 0 deletions src/Either.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,17 @@ describe('Either', () => {
expect(e.isLeft()).toBe(false);
});
});
describe('.proceedLeft', () => {
test('handles regular functions', () => {
const e = Either.left('test');
expect(e.proceedLeft((x) => Either.left(x + 'ing')).getLeft()).toBe('testing');
});
test('handles async functions', async () => {
const e = Either.left('test');
const proceeded = await e.proceedLeft((x) =>
Promise.resolve(Either.left(x + 'ing'))
);
expect(proceeded.getLeft()).toBe('testing');
});
});
});
28 changes: 10 additions & 18 deletions src/Either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ export class Either<L, R> {
*
* @param lFunc
*/
public proceedLeft<T>(lFunc: (val: L) => Either<T, R>): Either<T, R> {
public proceedLeft<T>(lFunc: (val: L) => Promise<Either<T, R>>): Promise<Either<T, R>>;
public proceedLeft<T>(lFunc: (val: L) => Either<T, R>): Either<T, R>;
public proceedLeft<T>(
lFunc: ((val: L) => Either<T, R>) | ((val: L) => Promise<Either<T, R>>)
): Either<T, R> | Promise<Either<T, R>> {
if (this.left.isPresent()) {
return lFunc(this.left.get());
}
Expand All @@ -144,23 +148,11 @@ export class Either<L, R> {
*
* @param rFunc
*/
public proceedRight<T>(rFunc: (val: R) => Either<L, T>): Either<L, T> {
if (this.right.isPresent()) {
return rFunc(this.right.get());
}

return Either.left<L, T>(this.left.get());
}

/**
* This provides an implementation of {@link proceedRightAsync} that can handle a mapping function
* that returns a `Promise<Either>`.
*
* @param rFunc
*/
public async proceedRightAsync<T>(
rFunc: (val: R) => Promise<Either<L, T>>
): Promise<Either<L, T>> {
public proceedRight<T>(rFunc: (val: R) => Promise<Either<L, T>>): Promise<Either<L, T>>;
public proceedRight<T>(rFunc: (val: R) => Either<L, T>): Either<L, T>;
public proceedRight<T>(
rFunc: ((val: R) => Either<L, T>) | ((val: R) => Promise<Either<L, T>>)
): Either<L, T> | Promise<Either<L, T>> {
if (this.right.isPresent()) {
return rFunc(this.right.get());
}
Expand Down
6 changes: 3 additions & 3 deletions src/Optional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('Optional', () => {
test('filters empty to empty', () => {
expect(
Optional.empty()
.filter((x) => true)
.filter(() => true)
.isPresent()
).toBe(false);
});
Expand Down Expand Up @@ -190,14 +190,14 @@ describe('Optional', () => {
expect(fn).toBeCalledWith(3);
});
test('calls a function with the value, if there is one and not the else function', () => {
const fn = vi.fn((v) => {});
const fn = vi.fn(() => {});
const elseFn = vi.fn(() => {});
Optional.of(3).ifPresent(fn).orElse(elseFn);
expect(fn).toBeCalledWith(3);
expect(elseFn).not.toBeCalled();
});
test("calls the else function without a value, if there isn't one", () => {
const fn = vi.fn((v) => {});
const fn = vi.fn(() => {});
const elseFn = vi.fn(() => {});
Optional.empty().ifPresent(fn).orElse(elseFn);
expect(fn).not.toBeCalled();
Expand Down
Loading
Loading