-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from functional-jslib/issue-30-issue-43-simpli…
…fy_slice_usage Issue 30 issue 43 simplify slice usage
- Loading branch information
Showing
131 changed files
with
5,998 additions
and
9,493 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
**/node_modules/**/* | ||
**/dist/**/*.js | ||
**/dist/**/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
|
||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.