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

Issue 30 issue 43 simplify slice usage #56

Merged
merged 25 commits into from
Nov 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
54db1f1
#30 - Progress on converting, convertible, occurrences of 'Slice<...>…
elycruz Jul 7, 2021
e0edcd3
Unstable - progress on simplifiying 'Slice' usage - Started convertin…
elycruz Jul 7, 2021
6705548
#30,#43 - Faster implementations of 'push', 'pushN' and 'reverse' met…
elycruz Aug 6, 2021
bbbdd8c
#30,#43 - Progress on replacing Slice calls with SliceInterface.
elycruz Sep 30, 2021
1d667a0
#30 - Progress on \SliceInterface\ replace, with Slice.
elycruz Oct 2, 2021
0731c3e
- Updated 'SliceInterface' to be just 'Slice'.
elycruz Oct 2, 2021
10f5945
#30 - \subsequence\ method optimize.
elycruz Oct 4, 2021
1d2fe34
Merged latest from upstreram.
elycruz Oct 4, 2021
fbde112
#30 - Unstable - progress on curry types upgrade and slice type upgra…
elycruz Oct 4, 2021
94c7285
Merge branch 'issue-30-issue-43-simplify_slice_usage' of github.com:f…
elycruz Oct 4, 2021
b96c498
#30 - Progress on slice types update.
elycruz Oct 4, 2021
1c605b9
#30 - Merged latest from upstream. Progress on Slice and Curry types.
elycruz Oct 4, 2021
a099ce1
#30 - Reverted 'strict' back to \ alse\, in root tsconfig. Updated t…
elycruz Oct 4, 2021
fcb80b4
#30 - Removed older, extraneous, curry types - simplified the set to …
elycruz Oct 8, 2021
6bcbbe7
#30 - Ran 'npm up'. Upgraded eslint version.
elycruz Oct 25, 2021
687dbd7
#30 - Removed legacy curry from 'equal' and 'platform/' modules - Rep…
elycruz Oct 25, 2021
28db84c
#30 - Removed a pointer from 'curryN' implementation.
elycruz Oct 25, 2021
bffe209
[unstable][ci-skip] - Progress on curry types refactor.
elycruz Oct 26, 2021
8d2919c
Progress on removing the use of 'curry*' methods.
elycruz Oct 26, 2021
6dc113f
#30 - Initial cleanup of curry types - Types are stabalized and allow…
elycruz Oct 28, 2021
e702231
#30 - Renamed fjl/.../subsequence to subsequences.
elycruz Oct 28, 2021
527bfcc
#30 - Added tests for MonadBase.
elycruz Oct 29, 2021
9666b86
#30 - Added tests for 'toRight' and 'toLeft', mostly to show these as…
elycruz Oct 29, 2021
3ce3b5e
Updated @typescrip-eslint/* package versions.
elycruz Nov 28, 2021
f6e1bf3
Updated failing test in fjl-validator.
elycruz Nov 28, 2021
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
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
**/node_modules/**/*
**/dist/**/*.js
**/dist/**/*
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"experimentalObjectRestSpread": true
}
},

"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
Expand Down
13,122 changes: 4,703 additions & 8,419 deletions package-lock.json

Large diffs are not rendered by default.

25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@
"private": true,
"devDependencies": {
"@rollup/plugin-node-resolve": "^11.2.0",
"@rollup/plugin-typescript": "^8.2.0",
"@types/jest": "^26.0.21",
"@rollup/plugin-typescript": "^8.3.0",
"@types/jest": "^27.0.2",
"@types/node": "^13.13.47",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"del": "^5.1.0",
"eslint": "^6.8.0",
"jest": "^27.0.4",
"jest-cli": "^27.0.4",
"rollup": "^2.50.6",
"eslint": "^8.1.0",
"jest": "^27.3.1",
"jest-cli": "^27.3.1",
"rollup": "^2.58.3",
"rollup-plugin-terser": "^7.0.2",
"ts-jest": "^27.0.2",
"ts-jest": "^27.0.7",
"ts-node": "^9.1.1",
"tslib": "^2.1.0",
"typescript": "^4.2.3"
"tslib": "^2.3.1",
"typescript": "^4.4.4"
},
"scripts": {
"test": "jest -c jest.config.js",
Expand All @@ -28,7 +28,8 @@
"test:fjl-inputfilter": "jest -c jest.config.js --selectProjects fjl-inputfilter",
"test:fjl-validator": "jest -c jest.config.js --selectProjects fjl-validator",
"build": "rollup --config rollup.config.js",
"link-and-build:packages": "node node_scripts/tasks/link-packages.js"
"link-and-build:packages": "node node_scripts/tasks/link-packages.js",
"link:packages": "npm run link-and-build:packages"
},
"repository": {
"type": "git",
Expand Down
5 changes: 5 additions & 0 deletions packages/fjl-inputfilter/package-lock.json

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

4 changes: 2 additions & 2 deletions packages/fjl-inputfilter/src/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Created by Ely on 7/24/2014.
*/
import {
apply, assign, compose, defineEnumProps, isArray, isset,
assign, compose, defineEnumProps, isArray, isset,
isString, Slice, Unary, error as defaultErrorHandler
} from 'fjl';
import {
Expand Down Expand Up @@ -198,7 +198,7 @@ export const
* Runs filters on value (successively).
*/
runFilters = <T = any>(filters: Unary<T, any>[], value: T): T | any => filters && filters.length ?
apply(compose, filters)(value) : value,
compose(...filters)(value) : value,

/**
* Runs filters on value (successively) and returns result wrapped in a promise.
Expand Down
5 changes: 4 additions & 1 deletion packages/fjl-inputfilter/tests/test-Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
validateIOInput
} from '../src/input';
import {runHasPropTypes} from "./utils";
import {log} from "../../fjl/tests/helpers";

const toSlug = (x: string): string => (x + '').replace(/[^a-z\d\-_]+/gim, '-').toLowerCase(),
trim = (x: string): string => x ? (x + '').trim() : x,
Expand Down Expand Up @@ -91,7 +92,9 @@ describe('#runValidators', function () {
]
.concat(
subsequences('hello')
.map(x => [runValidators(inputOptionObjs[0].validators, breakOnFailure, (x as string[]).join('')), true, 0])
.map(x => {
return [runValidators(inputOptionObjs[0].validators, breakOnFailure, x), true, 0]
})
))
.forEach(([rsltObj, expectedResult, expectedMsgsLen]) => {
const {result, messages} = rsltObj;
Expand Down
88 changes: 45 additions & 43 deletions packages/fjl-inputfilter/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
import {range, apply} from 'fjl';
import {range} from 'fjl';
import {TypeRef} from "../../fjl/src";

export const

genRan = (min, max) => Math.round(Math.random() * max),

genRanChar = (min = 0, max = 0x10FFFF) =>
String.fromCharCode(genRan(min, max)),

genRanStr = (min = 0, max = 100) =>
range(min, max)
.reduce(str => str + genRanChar(min, max), ''),

runHasPropOfType = (Type, propName, [correctValue, incorrectValue], x) => {
test (`it should have an \`${propName}\` property`, () => {
expect(Object.prototype.hasOwnProperty.call(x, propName)).toEqual(true);
});
test (`it should throw an error when setting \`${propName}\` to ${incorrectValue}`, () => {
expect(() => { x[propName] = incorrectValue; }).toThrow(Error);
});
test (`it should set value correctly for \`${propName}\` when value is of correct type`, () => {
x[propName] = correctValue;
expect(x[propName]).toEqual(correctValue);
});
},

runHasPropOfTypeUnWrapped = (Type, propName, [correctValue, incorrectValue], x) => {
expect(Object.prototype.hasOwnProperty.call(x, propName)).toEqual(true);
expect(() => { x[propName] = incorrectValue; }).toThrow(Error);
x[propName] = correctValue;
expect(x[propName]).toEqual(correctValue);
},

runHasPropTypes = (propTypeArgsList, x) =>
propTypeArgsList.forEach(args => {
const _args = args.slice(0);
_args.push(x);
apply(runHasPropOfType, _args);
}),

runHasPropTypesUnWrapped = (propTypeArgsList, x) =>
propTypeArgsList.forEach(args => {
const _args = args.slice(0);
_args.push(x);
apply(runHasPropOfTypeUnWrapped, _args);
})
genRan = (min: number, max: number) => Math.round(Math.random() * max),

genRanChar = (min = 0, max = 0x10FFFF) =>
String.fromCharCode(genRan(min, max)),

genRanStr = (min = 0, max = 100) =>
range(min, max)
.reduce(str => str + genRanChar(min, max), ''),

runHasPropOfType = (Type: TypeRef, propName: string, [correctValue, incorrectValue]: [any, any], x: any): void => {
test(`it should have an \`${propName}\` property`, () => {
expect(Object.prototype.hasOwnProperty.call(x, propName)).toEqual(true);
});
test(`it should throw an error when setting \`${propName}\` to ${incorrectValue}`, () => {
expect(() => {
x[propName] = incorrectValue;
}).toThrow(Error);
});
test(`it should set value correctly for \`${propName}\` when value is of correct type`, () => {
x[propName] = correctValue;
expect(x[propName]).toEqual(correctValue);
});
},

runHasPropOfTypeUnWrapped = (Type, propName, [correctValue, incorrectValue], x) => {
expect(Object.prototype.hasOwnProperty.call(x, propName)).toEqual(true);
expect(() => {
x[propName] = incorrectValue;
}).toThrow(Error);
x[propName] = correctValue;
expect(x[propName]).toEqual(correctValue);
};

type RunHasPropOfType = typeof runHasPropOfType;
type RunHasPropOfTypesUnWrapped = typeof runHasPropOfTypeUnWrapped;
type P = Parameters<RunHasPropOfType>;
type P2 = Parameters<RunHasPropOfTypesUnWrapped>;

export const runHasPropTypes = (propTypeArgsList: [P[0], P[1], P[2]][], x) =>
propTypeArgsList.forEach(args => runHasPropOfType(...(args.concat([x]) as P))),

runHasPropTypesUnWrapped = (propTypeArgsList: [P2[0], P2[1], P2[2]][], x) =>
propTypeArgsList.forEach(args => runHasPropOfTypeUnWrapped(...(args.concat([x])) as P2))

;
4 changes: 2 additions & 2 deletions packages/fjl-validator-recaptcha/tests/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {apply, log, peek, range} from 'fjl';
import {log, peek, range} from 'fjl';

export {log, peek};

Expand Down Expand Up @@ -32,7 +32,7 @@ export const
propTypeArgsList.forEach(args => {
const _args = args.slice(0);
_args.push(x);
apply(runHasPropOfType, _args);
runHasPropOfType(..._args);
})

;
5 changes: 5 additions & 0 deletions packages/fjl-validator/package-lock.json

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

2 changes: 1 addition & 1 deletion packages/fjl-validator/tests/test-stringLengthValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('#toStringLengthOptions', function () {
describe('#stringLengthValidator', function () {
const testArgs = (subsequences('hello')
.concat([repeat(21, 'a'), repeat(14, 'b')]) as string[][])
.map(x => x.join(''));
.map(x => x instanceof Array ? x.join('') : x);
test('should return a validation result object with a `result` of `false` and ' +
'one error message when value is not of type `String`', function () {
const strValidator = stringLengthValidator(null);
Expand Down
46 changes: 46 additions & 0 deletions packages/fjl/designs/curry.designs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

## Why "unidiomatic" curry is difficult (in typescript):

### Reason 1:
Types for the following (etc.) are required:

#### `curry2`
```
(a, b) -> c
a -> b -> c
```

#### `curry3`
```
(a, b, c) -> d
(a, b) -> c -> d
a -> b -> c -> d
a -> (b, c) -> d
```

#### `curry4`:

```
(a, b, c, d) -> e
(a, b, c) -> d -> e
(a, b) -> c -> d -> e
a -> b -> c -> d -> e
a -> b -> (c, d) -> e
a -> (b, c, d) -> e
(a, b) -> (c, d) -> e
```

#### `curry5`:

```
(a, b, c, d, e) -> f
(a, b, c, d) -> e -> f
(a, b, c) -> d -> e -> f
(a, b) -> c -> d -> e -> f
a -> b -> c -> d -> e -> f
a -> b -> c -> (d, e) -> f
a -> b -> (c, d, e) -> f
a -> (b, c, d, e) -> f
(a, b) -> (c, d, e) -> f
(a, b, c) -> (d, e) -> f
```
5 changes: 5 additions & 0 deletions packages/fjl/package-lock.json

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

11 changes: 5 additions & 6 deletions packages/fjl/src/boolean/equal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {curry2, CurryPred2} from '../function/curry';

/**
* Equality combinator.
*/
export const

equal = <T>(a: T, b: T): boolean => a === b,
import {curry2, CurryOf2} from "../function";

$equal = curry2(equal) as CurryPred2<any>;
export const equal = <T = any>(a: T, b: T): boolean => a === b;
export type Equal = typeof equal;
export type EqualParams = Parameters<Equal>;
export const $equal = curry2(equal) as CurryOf2<EqualParams[0], EqualParams[1], ReturnType<Equal>>;
2 changes: 1 addition & 1 deletion packages/fjl/src/boolean/isFalsy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
/**
* Returns whether `value` is 'falsy' or not
*/
export const isFalsy = <T>(value: T): boolean => !value;
export const isFalsy = (value: any): boolean => !value;

2 changes: 1 addition & 1 deletion packages/fjl/src/boolean/isTruthy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/**
* Returns whether `value` is 'truthy' or not.
*/
export const isTruthy = <T>(value: T): boolean => !!value;
export const isTruthy = (value: any): boolean => !!value;
21 changes: 12 additions & 9 deletions packages/fjl/src/data/either.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* Created by elyde on 12/10/2016.
*/
import {isset} from '../object/isset';
import {curry} from '../function/curry';
import {id} from '../function/id';
import {MonadBase} from './monad';
import {FunctorMapFn} from "../types";
import {curry3, CurryOf3} from "../function";

export type Either<A, B> = A | B;
export type Either<A, B> = Right<A> | Right<B>;

/**
* `Left` representation of `Either` construct.
Expand Down Expand Up @@ -79,19 +79,22 @@ export const
* Converts given to an either (`Right`|`Left`)
*/
toEither = <A, B>(x: A): Either<Right<A>, Left<B>> =>
(isLeft(x) || isRight(x) ? x : right(x).map(id)) as Either<Right<A>, Left<B>>,
(isLeft(x) || isRight(x) ? x : (!isset(x) ? left(x) : right(x).map(id))) as Either<Right<A>, Left<B>>,

/**
* Calls matching callback on incoming `Either`; If it's an `Left` type, calls left-callback on it,
* If it's an `Right` type, calls the right-callback on it.
* Returns value of the flat-mapped monad.
*/
either = <A, B, C>(leftCallback: FunctorMapFn<C>, rightCallback: FunctorMapFn<C>, _either_: Left<A> | Right<B>): C =>
_either_.map(isRight(_either_) ? rightCallback : leftCallback).join(),
_either_.map(isRight(_either_) ? rightCallback : leftCallback).join();

/**
* Curried version `either`.
*/
$either = curry(either)
export type EitherFn = typeof either;

export type EitherFnParams = Parameters<EitherFn>;

;
/**
* Curried version `either`.
*/
export const $either =
curry3(either) as CurryOf3<EitherFnParams[0], EitherFnParams[1], EitherFnParams[2], ReturnType<EitherFn>>;
Loading