Skip to content

Commit

Permalink
feat: curry 加类型
Browse files Browse the repository at this point in the history
  • Loading branch information
Vic committed Nov 5, 2020
1 parent 2665629 commit 60da03b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions packages/functional/src/util/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { Left, Right } from ".."

export const partial = (fn, ...presetArgs) =>
(...laterArgs) =>
interface anyFn {
(...args: any): any
}

interface partialType<RType> {
(...args: any): RType
}

export function partial<T extends anyFn> (fn: T, ...presetArgs): partialType<ReturnType<T>> {
return (...laterArgs) =>
fn(...presetArgs, ...laterArgs)
}

export const curry = (fn, arity: number = fn.length, nextCurried?: any) =>
(nextCurried = prevArgs =>
Expand All @@ -27,4 +36,10 @@ export const either = curry((leftFn, rightFn, functor) => {
})



var haha = curry(
(a, b): number => a + b
)
var hehe = haha(3)

console.log(hehe);

0 comments on commit 60da03b

Please sign in to comment.