Skip to content

Commit

Permalink
Merge pull request #15 from functional-jslib/next-curry-refactor
Browse files Browse the repository at this point in the history
Next curry refactor
  • Loading branch information
elycruz authored Nov 3, 2019
2 parents 4ccfec2 + c54ccc0 commit e89a527
Show file tree
Hide file tree
Showing 27 changed files with 1,669 additions and 1,688 deletions.
236 changes: 13 additions & 223 deletions .eslintrc

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Functional Javascript Library (inspired by Haskell's Prelude).
## Getting Started:

#### Note on typescript:
If you are using typescript, and want to manually include fjl's types file, it is located at `'fjl/types/index.d.ts'`.
If you are using typescript, and want to manually include fjl's types file, it is located at `'fjl/types/index.ts'`.

### In Browser:
See desired export type below:
Expand Down Expand Up @@ -326,7 +326,7 @@ live directly on 'fjl' and are defined in 'fjl/objects/defineProp' (or more dire
- Cleaned up imports in some places to protect from cyclic dependency issues.

### 1.5.1, 1.5.2
- Added './types/index.d.ts' file.
- Added './types/index.ts' file.

### 1.5.0
#### Breaking changes
Expand Down
7 changes: 3 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module.exports = {
presets: [['@babel/preset-env']],
plugins: [
'@babel/plugin-syntax-object-rest-spread',
'@babel/plugin-proposal-object-rest-spread'
presets: [
'@babel/preset-typescript',
'@babel/preset-env'
]
};
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h3>Supported Platforms:</h3><h4>Browsers</h4><ul>
<h4>NodeJs</h4><ul>
<li>8+</li>
</ul>
<h2>Getting Started:</h2><h4>Note on typescript:</h4><p>If you are using typescript, and want to manually include fjl's types file, it is located at <code>'fjl/types/index.d.ts'</code>.</p>
<h2>Getting Started:</h2><h4>Note on typescript:</h4><p>If you are using typescript, and want to manually include fjl's types file, it is located at <code>'fjl/types/index.ts'</code>.</p>
<h3>In Browser:</h3><p>See desired export type below:</p>
<ul>
<li>'./dist/amd/' - Asynchronous module format.</li>
Expand Down Expand Up @@ -305,7 +305,7 @@ <h3>1.6.0</h3><ul>
<li>Cleaned up imports in some places to protect from cyclic dependency issues.</li>
</ul>
<h3>1.5.1, 1.5.2</h3><ul>
<li>Added './types/index.d.ts' file.</li>
<li>Added './types/index.ts' file.</li>
</ul>
<h3>1.5.0</h3><h4>Breaking changes</h4><ul>
<li><code>reduceRightUntil</code> changed to <code>reduceUntilRight</code>.</li>
Expand Down
2 changes: 1 addition & 1 deletion markdown-fragments/sections/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ live directly on 'fjl' and are defined in 'fjl/objects/defineProp' (or more dire
- Cleaned up imports in some places to protect from cyclic dependency issues.

### 1.5.1, 1.5.2
- Added './types/index.d.ts' file.
- Added './types/index.ts' file.

### 1.5.0
#### Breaking changes
Expand Down
3 changes: 0 additions & 3 deletions markdown-fragments/sections/getting-started.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
## Getting Started:

#### Note on typescript:
If you are using typescript, and want to manually include fjl's types file, it is located at `'fjl/types/index.d.ts'`.

### In Browser:
See desired export type below:
- './dist/amd/' - Asynchronous module format.
Expand Down
2 changes: 1 addition & 1 deletion markdown-fragments/sections/motivations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- Haskell and it's `Prelude` (Functional programming).
- Lambda Calculus.
- The need for:
- functional 'combinators' in javascript (without requiring typescript) (index.d.ts being developed for typescript users).
- functional 'combinators' in javascript (without requiring typescript) (index.ts being developed for typescript users).
- the ability to write functional code quickly and easily (using the likes of `curry`, `isset`, `compose` etc.).
- a library written from the ground up using es6 and functional concepts.
- a library that is exported to multiple formats (umd, amd, commonjs, es6-modules, and iife).
Expand Down
45 changes: 23 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,47 @@
"lib": "src"
},
"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.4",
"@babel/parser": "^7.5.0",
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/parser": "^7.6.4",
"@babel/plugin-external-helpers": "^7.2.0",
"@babel/plugin-proposal-object-rest-spread": "^7.5.4",
"@babel/plugin-proposal-object-rest-spread": "^7.6.2",
"@babel/plugin-syntax-bigint": "^7.4.4",
"@babel/plugin-syntax-object-rest-spread": "^7.2.0",
"@babel/polyfill": "^7.4.4",
"@babel/preset-env": "^7.5.4",
"@babel/preset-typescript": "^7.3.3",
"@babel/register": "^7.4.4",
"@babel/types": "^7.5.0",
"@types/jest": "^24.0.15",
"@types/node": "^12.6.2",
"@typescript-eslint/parser": "^1.11.0",
"@babel/polyfill": "^7.6.0",
"@babel/preset-env": "^7.6.3",
"@babel/preset-typescript": "^7.6.0",
"@babel/register": "^7.6.2",
"@babel/types": "^7.6.3",
"@types/jest": "^24.0.21",
"@types/node": "^12.12.5",
"@typescript-eslint/eslint-plugin": "^2.6.0",
"@typescript-eslint/parser": "^2.6.0",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.8.0",
"babel-jest": "^24.9.0",
"babel-plugin-add-module-exports": "^1.0.2",
"babel-preset-es2015-rollup": "^3.0.0",
"del": "^5.0.0",
"eslint": "^6.0.1",
"del": "^5.1.0",
"eslint": "^6.6.0",
"gulp": "4.0.2",
"gulp-babel": "^8.0.0",
"gulp-better-rollup": "^4.0.1",
"gulp-concat": "^2.6.1",
"gulp-duration": "0.0.0",
"gulp-eslint": "^6.0.0",
"gulp-header": "^2.0.7",
"gulp-if": "^2.0.2",
"gulp-header": "^2.0.9",
"gulp-if": "^3.0.0",
"gulp-jsdoc3": "^2.0.0",
"gulp-replace": "^1.0.0",
"gulp-uglify": "^3.0.2",
"jest": "^24.8.0",
"rollup": "^1.16.7",
"jest": "^24.9.0",
"rollup": "^1.26.3",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-node-resolve": "^5.2.0",
"ts-jest": "^24.0.2",
"ts-node": "^8.3.0",
"ts-jest": "^24.1.0",
"ts-node": "^8.4.1",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^3.5.3"
"typescript": "^3.6.4"
},
"repository": {
"type": "git",
Expand Down
7 changes: 4 additions & 3 deletions src/boolean/equal.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import {curry} from '../function/curry';
import {BinaryPred} from "../types";

export const

/**
* Equality operator.
* @function module:boolean.equal
* @param a {*}
* @param b {*}
* @param [a=undefined] {any}
* @param [b=undefined] {any}
* @returns {boolean}
*/
equal = curry((a, b) => a === b);
equal: BinaryPred<any> = curry((a, b) => a === b) as BinaryPred<any>;
6 changes: 5 additions & 1 deletion src/boolean/equalAll.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import {curry2} from '../function/curry';
import {equal} from './equal';
import {PolyPred} from "../types";

export const
/**
* Equality operator for all.
* @curried - Curried at upto 2 args.
* @function module:boolean.equalAll
* @param a {*} - Item `0`.
* @param args {...*} - Others
* @returns {boolean}
*/
equalAll = curry2((a, ...args) => args.every(b => equal(a, b)));
equalAll: PolyPred<any> = curry2((a, ...args) =>
args.every(b => equal(a, b))
) as PolyPred<any>;
4 changes: 3 additions & 1 deletion src/boolean/isFalsy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {UnaryPred} from "../types";

export const

/**
Expand All @@ -6,4 +8,4 @@ export const
* @param value
* @returns {Boolean}
*/
isFalsy = value => !value;
isFalsy: UnaryPred<any> = value => !value;
4 changes: 3 additions & 1 deletion src/boolean/isTruthy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {UnaryPred} from "../types";

export const

/**
Expand All @@ -6,4 +8,4 @@ export const
* @param value
* @returns {Boolean}
*/
isTruthy = value => !!value;
isTruthy: UnaryPred<any> = value => !!value;
19 changes: 13 additions & 6 deletions src/data/Functor.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
import {isset} from '../object/isset';
import {MapFunc} from "../types";

export const toFunctor = x => !isset(x) || !x.map ? new Functor(x) : x;
export const toFunctor = (x: any): Functor<any> => !isset(x) || !x.map ? new Functor(x) : x;

export default class Functor<T> {
readonly value?:T;
constructor(value?: T) {this.value = value;}
readonly value?: T;

constructor(value?: T) {
this.value = value;
}

valueOf(): T {
return this.value;
}
map(fn: (x: T) => T): Functor<T> {
return new Functor(fn(this.valueOf()));

map(fn: MapFunc<T, Functor<T>>): Functor<T> {
return new Functor(fn(this.valueOf(), 0, this));
}
fmap (fn: (x: T) => T): Functor<T> {

fmap(fn: MapFunc<T, Functor<T>>): Functor<T> {
return this.map(fn);
}
}
7 changes: 4 additions & 3 deletions src/errorThrowing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@
import {typeOf} from '../object/typeOf';
import {isArray, toTypeRef, toTypeRefName, isOfType} from '../object/is';
import {curry} from '../function/curry';
import {TypeRef} from "../types";

export const

/**
* Pretty prints an array of types/type-strings for use by error messages;
* Outputs "`SomeTypeName`, ..." from [SomeType, 'SomeTypeName', etc...]
* @function module:errorThrowing.typeRefsToStringOrError
* @param types {Array|TypesArray}
* @param types {Array<TypeRef>}
* @return {String}
* @private
*/
typeRefsToStringOrError = types => types.length ?
typeRefsToStringOrError = (types: TypeRef[]): string => types.length ?
types.map(type => `\`${toTypeRefName(type)}\``).join(', ') : '',

/**
* Prints a message from an object. Object signature:
* {contextName, valueName, value, expectedTypeName, foundTypeName, messageSuffix}
* @function module:errorThrowing.defaultErrorMessageCall
* @param tmplContext {Object|TemplateContext} - Object to use in error template.
* @param tmplContext {Object|ErrorTemplateContext} - Object to use in error template.
* @returns {index.ts}
* @private
*/
Expand Down
Loading

0 comments on commit e89a527

Please sign in to comment.