-
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.
feat: Adding Functional programming support
- Loading branch information
Showing
62 changed files
with
1,035 additions
and
49 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
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,31 @@ | ||
/** | ||
* @module @promises/-fp | ||
* @copyright © 2017 Yisrael Eliav <yisraelx@gmail.com> (https://github.com/yisraelx) | ||
* @license MIT | ||
*/ | ||
|
||
export { default as error } from '@promises/error/fp'; | ||
export { default as everyParallel } from '@promises/every-parallel/fp'; | ||
export { default as everySeries } from '@promises/every-series/fp'; | ||
export { default as filterParallel } from '@promises/filter-parallel/fp'; | ||
export { default as filterSeries } from '@promises/filter-series/fp'; | ||
export { default as finally } from '@promises/finally/fp'; | ||
export { default as forEachParallel } from '@promises/for-each-parallel/fp'; | ||
export { default as forEachRightSeries } from '@promises/for-each-right-series/fp'; | ||
export { default as forEachSeries } from '@promises/for-each-series/fp'; | ||
export * from '@promises/interfaces'; | ||
export { default as mapParallel } from '@promises/map-parallel/fp'; | ||
export { default as mapSeries } from '@promises/map-series/fp'; | ||
export { default as next } from '@promises/next/fp'; | ||
export { default as reduceRightSeries } from '@promises/reduce-right-series/fp'; | ||
export { default as reduceSeries } from '@promises/reduce-series/fp'; | ||
export { default as rejectParallel } from '@promises/reject-parallel/fp'; | ||
export { default as rejectSeries } from '@promises/reject-series/fp'; | ||
export { default as reset } from '@promises/reset/fp'; | ||
export { default as sleep } from '@promises/sleep/fp'; | ||
export { default as someParallel } from '@promises/some-parallel/fp'; | ||
export { default as someSeries } from '@promises/some-series/fp'; | ||
export { default as timesParallel } from '@promises/times-parallel/fp'; | ||
export { default as timesSeries } from '@promises/times-series/fp'; | ||
export { default as toCallback } from '@promises/to-callback/fp'; | ||
export { default as wait } from '@promises/wait/fp'; |
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,61 @@ | ||
{ | ||
"name": "@promises/-fp", | ||
"version": "NEXT-PLACEHOLDER", | ||
"description": "FP is a group of packages of Promises library", | ||
"main": "es5.js", | ||
"browser": "umd.min.js", | ||
"module": "index.js", | ||
"es2015": "index.js", | ||
"typings": "index.d.ts", | ||
"bundle": "bundle.min.js", | ||
"author": { | ||
"name": "Yisrael Eliev", | ||
"url": "https://github.com/yisraelx", | ||
"email": "yisraelx@gmail.com" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"promise", | ||
"promises", | ||
"utility", | ||
"modules", | ||
"async", | ||
"await", | ||
"deferred" | ||
], | ||
"homepage": "https://github.com/yisraelx/promises#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/yisraelx/promises.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/yisraelx/promises/issues" | ||
}, | ||
"dependencies": { | ||
"@promises/error": "^0.3.1", | ||
"@promises/every-parallel": "^0.3.1", | ||
"@promises/every-series": "^0.3.1", | ||
"@promises/filter-parallel": "^0.3.1", | ||
"@promises/filter-series": "^0.3.1", | ||
"@promises/finally": "^0.3.1", | ||
"@promises/for-each-parallel": "^0.3.1", | ||
"@promises/for-each-right-series": "^0.3.1", | ||
"@promises/for-each-series": "^0.3.1", | ||
"@promises/interfaces": "^0.3.0", | ||
"@promises/map-parallel": "^0.3.1", | ||
"@promises/map-series": "^0.3.1", | ||
"@promises/next": "^0.3.1", | ||
"@promises/reduce-right-series": "^0.3.1", | ||
"@promises/reduce-series": "^0.3.1", | ||
"@promises/reject-parallel": "^0.3.1", | ||
"@promises/reject-series": "^0.3.1", | ||
"@promises/reset": "^0.3.1", | ||
"@promises/sleep": "^0.3.1", | ||
"@promises/some-parallel": "^0.3.1", | ||
"@promises/some-series": "^0.3.1", | ||
"@promises/times-parallel": "^0.3.1", | ||
"@promises/times-series": "^0.3.1", | ||
"@promises/to-callback": "^0.3.1", | ||
"@promises/wait": "^0.3.1" | ||
} | ||
} |
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,32 @@ | ||
/** | ||
* @module @promises/_curry | ||
* @copyright © 2017 Yisrael Eliav <yisraelx@gmail.com> (https://github.com/yisraelx) | ||
* @license MIT | ||
*/ | ||
|
||
export interface ICurryOptions { | ||
length?: number; | ||
order?: number[]; | ||
} | ||
|
||
export default function _curry(fn: Function, { length = fn.length, order}: ICurryOptions = {}) { | ||
order = Array.isArray(order) ? order : [length - 1].concat(Array.apply(null, Array(length - 1)).map((v, i) => i)); | ||
|
||
let next = (allArgs: any[]) => { | ||
if (allArgs.length >= length) { | ||
let execArgs = Array(length); | ||
for (let i = 0; i < length; i++) { | ||
let index = order[i]; | ||
let value = allArgs[index]; | ||
execArgs[i] = value; | ||
} | ||
return fn.apply(null, execArgs); | ||
} | ||
return (...currentArgs: any[]) => { | ||
allArgs = allArgs.concat(currentArgs); | ||
return next(allArgs); | ||
}; | ||
}; | ||
|
||
return next([]); | ||
} |
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,34 @@ | ||
{ | ||
"name": "@promises/_curry", | ||
"version": "0.3.0", | ||
"description": "Curry is a internal package from Promises library", | ||
"main": "es5.js", | ||
"browser": "umd.min.js", | ||
"module": "index.js", | ||
"es2015": "index.js", | ||
"typings": "index.d.ts", | ||
"bundle": "bundle.min.js", | ||
"author": { | ||
"name": "Yisrael Eliev", | ||
"url": "https://github.com/yisraelx", | ||
"email": "yisraelx@gmail.com" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
"promise", | ||
"promises", | ||
"utility", | ||
"modules", | ||
"async", | ||
"await", | ||
"deferred" | ||
], | ||
"homepage": "https://github.com/yisraelx/promises#readme", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/yisraelx/promises.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/yisraelx/promises/issues" | ||
} | ||
} |
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,28 @@ | ||
import _curry from '@promises/_curry'; | ||
import { IOptionalPromise } from '@promises/interfaces'; | ||
import error from './'; | ||
|
||
export interface IError { | ||
<R>(newValue: IOptionalPromise<any>, value: IOptionalPromise<R>): Promise<R>; | ||
<R>(newValue: IOptionalPromise<any>): (value: IOptionalPromise<R>) => Promise<R>; | ||
} | ||
|
||
/** | ||
* @example | ||
* | ||
* ```typescript | ||
* let promise: Promise<string> = Promise.reject<string>('foo'); | ||
* error('bar')()(promise).catch((error: string) => { | ||
* console.log(error); // => 'bar' | ||
* }); | ||
* ``` | ||
* @example | ||
* | ||
* ```typescript | ||
* let promise: Promise<string> = Promise.resolve<string>('foo'); | ||
* error('bar', promise).catch((error: string) => { | ||
* console.log(error); // => 'bar' | ||
* }); | ||
* ``` | ||
*/ | ||
export default _curry(error, {length: 2}) as IError; |
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,29 @@ | ||
import _curry from '@promises/_curry'; | ||
import { IOptionalPromise, IOptionalPromiseDictionary } from '@promises/interfaces'; | ||
import everyParallel from './'; | ||
|
||
export interface IEveryParallel { | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>, limit: number, array: IOptionalPromise<T>): Promise<boolean>; | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>, limit: number): (array: IOptionalPromise<T>) => Promise<boolean>; | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>): (limit: number) => (array: IOptionalPromise<T>) => Promise<boolean>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>, limit: number, object: IOptionalPromiseDictionary<T>): Promise<boolean>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>, limit: number): (object: IOptionalPromiseDictionary<T>) => Promise<boolean>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>): (limit: number) => (object: IOptionalPromiseDictionary<T>) => Promise<boolean>; | ||
} | ||
|
||
/** | ||
* @example | ||
* | ||
* ```typescript | ||
* let comparator = (value) => { | ||
* return Promise.resolve(Boolean(value)) | ||
* }; | ||
* | ||
* let array: any[] = [true, 1, Promise.resolve(null), 'yes']; | ||
* | ||
* everyParallel(comparator)(Infinity)(array).then((result: boolean)=>{ | ||
* console.log(result) // result => false | ||
* }); | ||
* ``` | ||
*/ | ||
export default _curry(everyParallel, {length: 3}) as IEveryParallel; |
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,27 @@ | ||
import _curry from '@promises/_curry'; | ||
import { IOptionalPromise, IOptionalPromiseDictionary } from '@promises/interfaces'; | ||
import everySeries from './'; | ||
|
||
export interface IEverySeries { | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>, array: IOptionalPromise<T>): Promise<boolean>; | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>): (array: IOptionalPromise<T>) => Promise<boolean>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>, object: IOptionalPromiseDictionary<T>): Promise<boolean>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>): (object: IOptionalPromiseDictionary<T>) => Promise<boolean>; | ||
} | ||
|
||
/** | ||
* @example | ||
* | ||
* ```typescript | ||
* let comparator = (value) => { | ||
* return Promise.resolve(Boolean(value)) | ||
* }; | ||
* | ||
* let array: any[] = [true, 1, Promise.resolve(null), 'yes']; | ||
* | ||
* everySeries(comparator)(array).then((result: boolean)=>{ | ||
* console.log(result) // result => false | ||
* }); | ||
* ``` | ||
*/ | ||
export default _curry(everySeries, {length: 2}) as IEverySeries; |
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,29 @@ | ||
import _curry from '@promises/_curry'; | ||
import { IOptionalPromise, IOptionalPromiseDictionary } from '@promises/interfaces'; | ||
import filterParallel from './'; | ||
|
||
export interface IFilterParallel { | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>, limit: number, array: IOptionalPromise<T>): Promise<T>; | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>, limit: number): (array: IOptionalPromise<T>) => Promise<T>; | ||
<T extends ArrayLike<any>>(iteratee: (value: T[keyof T & number], index: number, array: T) => IOptionalPromise<boolean>): (limit: number) => (array: IOptionalPromise<T>) => Promise<T>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>, limit: number, object: IOptionalPromiseDictionary<T>): Promise<T>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>, limit: number): (object: IOptionalPromiseDictionary<T>) => Promise<T>; | ||
<T>(iteratee: (value: T[keyof T], key: keyof T, object: T) => IOptionalPromise<boolean>): (limit: number) => (object: IOptionalPromiseDictionary<T>) => Promise<T>; | ||
} | ||
|
||
/** | ||
* @example | ||
* | ||
* ```typescript | ||
* let comparator = (value: number) => { | ||
* return value % 2 === 0; | ||
* }; | ||
* | ||
* let array = Array.from({length:5}, (value, index) => index); | ||
* | ||
* filterParallel(comparator)(void 0, array).then((result: number[])=>{ | ||
* console.log(result); // result => [0, 2, 4] | ||
* }); | ||
* ``` | ||
*/ | ||
export default _curry(filterParallel, {length: 3}) as IFilterParallel; |
Oops, something went wrong.