UNPKG

@typed-f/function

Version:

[![NPM Version][function-npm-version-badge]][function-npm] [repo-circleci-badge]: https://img.shields.io/circleci/project/github/Ailrun/typed-f/master.svg?logo=circleci [![Known Vulnerabilities][function-snyk-badge]][function-snyk] [![Supported TypeScript

33 lines (25 loc) 613 B
/* * Copyright 2018-present Junyoung Clare Jang */ import { Fun } from './'; export function _createCurried<F extends Fun>( f: F, arity: number, args: any[], ) { function curried(this: any) { const length = arguments.length; if (length === 0) { return curried; } let index = length; const nextArgs = []; while (index--) { nextArgs[index] = arguments[index]; } if (args.length + length >= arity) { return f.apply(this, args.concat(nextArgs).slice(0, arity)); } return _createCurried(f, arity, args.concat(nextArgs)); } return curried; }