-
Notifications
You must be signed in to change notification settings - Fork 7
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 #31 from Jozty/typesv2
refine types
- Loading branch information
Showing
139 changed files
with
1,995 additions
and
443 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
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
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
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,25 +1,33 @@ | ||
import curryN from "./utils/curry_n.ts" | ||
import { Curry1, Func } from "./utils/types.ts" | ||
import { max } from './max.ts' | ||
import { pluck } from './pluck.ts' | ||
import { reduce } from './reduce.ts' | ||
import { PH, Func, Predicate } from "./utils/types.ts" | ||
import { getFunctionsLengths } from "./utils/get.ts" | ||
|
||
function _anyPass(preds: any) { | ||
let len = preds.length | ||
let fn = function(this: any) { | ||
// @types | ||
type AnyPass = (<T>(predicates: Predicate<T>[]) => Func) | ||
& ((predicates?: PH) => AnyPass) | ||
|
||
function _anyPass<T>(predicates: Predicate<T>[]) { | ||
const len = predicates.length | ||
const fn = function(this: any, ...args: T[]) { | ||
for(let idx = 0; idx < len; idx++){ | ||
if (preds[idx].apply(this, arguments)) { | ||
if (predicates[idx].apply(this, args)) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
return curryN(reduce(max, 0, pluck('length', preds)), fn) | ||
|
||
const noOfParams = getFunctionsLengths(predicates) | ||
|
||
return curryN( | ||
Math.max(...noOfParams, 0), | ||
fn | ||
) | ||
} | ||
|
||
/** | ||
* Takes a list of predicates and returns a predicate that returns true for a | ||
* given list of arguments if at least one of the provided predicates is | ||
* satisfied by those arguments. | ||
*/ | ||
export const anyPass: Curry1<any, Func> = curryN(1, _anyPass) | ||
export const anyPass: AnyPass = curryN(1, _anyPass) |
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.