utils.d.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * Utils includes
  3. * - a handful of functional utilities inspired by or taken from the [Ramda library](https://ramdajs.com/);
  4. * - TypeScript crutches - the [[tup]] function.
  5. *
  6. * Use these for your convenience - they are here so that urx is zero-dependency package.
  7. *
  8. * @packageDocumentation
  9. */
  10. /** @internal */
  11. export interface Proc {
  12. (): any;
  13. }
  14. /**
  15. * Performs left to right composition of two functions.
  16. */
  17. export declare function compose<I, A, R>(a: (arg: A) => R, b: (arg: I) => A): (arg: I) => R;
  18. /**
  19. * Takes a value and applies a function to it.
  20. */
  21. export declare function thrush<I, K>(arg: I, proc: (arg: I) => K): K;
  22. /**
  23. * Takes a 2 argument function and partially applies the first argument.
  24. */
  25. export declare function curry2to1<T, K, R>(proc: (arg1: T, arg2: K) => R, arg1: T): (arg2: K) => R;
  26. /**
  27. * Takes a 1 argument function and returns a function which when called, executes it with the provided argument.
  28. */
  29. export declare function curry1to0<T, R>(proc: (arg: T) => R, arg: T): () => R;
  30. /**
  31. * Returns a function which extracts the property from from the passed object.
  32. */
  33. export declare function prop(property: string): (object: any) => any;
  34. /**
  35. * Calls callback with the first argument, and returns it.
  36. */
  37. export declare function tap<T>(arg: T, proc: (arg: T) => any): T;
  38. /**
  39. * Utility function to help typescript figure out that what we pass is a tuple and not a generic array.
  40. * Taken from (this StackOverflow tread)[https://stackoverflow.com/questions/49729550/implicitly-create-a-tuple-in-typescript/52445008#52445008]
  41. */
  42. export declare function tup<T extends Array<any>>(...args: T): T;
  43. /**
  44. * Calls the passed function.
  45. */
  46. export declare function call(proc: Proc): void;
  47. /**
  48. * returns a function which when called always returns the passed value
  49. */
  50. export declare function always<T>(value: T): () => T;
  51. /**
  52. * returns a function which calls all passed functions in the passed order.
  53. * joinProc does not pass arguments or collect return values.
  54. */
  55. export declare function joinProc(...procs: Proc[]): () => void;
  56. export declare function noop(): void;