Last active
November 24, 2019 23:34
-
-
Save Darkle/ff53d856587f448fbb0c2bb285b7fac8 to your computer and use it in GitHub Desktop.
My TypeScript FP Utility Functions
This file contains hidden or 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
| const noop = (): void => {} | |
| const identity = <T>(param: T): T => param | |
| const pipe = (...fns: Function[]): Function => (param: any) => fns.reduce((result, fn) => fn(result), param) | |
| const compose = (...fns: Function[]): Function => (param: any) => fns.reduceRight((acc, current) => current(acc), param) | |
| const curry = (f: Function): Function => (...a: any[]) => (...b: any[]) => f(...a, ...b) | |
| const curryRight = (f: Function): Function => (...a: any[]) => (...b: any[]) => f(...b, ...a) | |
| const range = (start: number, end: number): number[] => Array.from({ length: (end - start) }, (v, k) => k + start) | |
| //includes end number - useful if you actually want the numbers in the range instead of just the index range | |
| const rangeIncEnd = (start: number, end: number): number[] => Array.from({ length: ((end - start) + 1) }, (v, k) => k + start) | |
| export{ | |
| noop, | |
| identity, | |
| pipe, | |
| compose, | |
| curry, | |
| curryRight, | |
| range, | |
| rangeIncEnd, | |
| } | |
| // Also check out https://github.com/ritesh404/kudojs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment