Ramda: Fix splitAt signature

- `splitAt` accepts either arrays or strings, not any arbitrary T.
- the output will always be an array of two elements, so switched to
  using the tuple syntax there.
- ensures that the overloading after first partial application works

http://ramdajs.com/docs/#splitAt

fixup splitat
This commit is contained in:
Miika Hänninen
2017-12-15 16:00:50 +02:00
parent 558e10c909
commit 4ab4a67990
2 changed files with 7 additions and 4 deletions

View File

@@ -1644,10 +1644,12 @@ declare namespace R {
/**
* Splits a given list or string at a given index.
*/
splitAt<T>(index: number, list: T): T[];
splitAt(index: number): <T>(list: T) => T[];
splitAt<T>(index: number, list: ReadonlyArray<T>): T[][];
splitAt(index: number): <T>(list: ReadonlyArray<T>) => T[][];
splitAt<T>(index: number, list: ReadonlyArray<T>): [T[], T[]];
splitAt(index: number, list: string): [string, string];
splitAt(index: number): {
<T>(list: ReadonlyArray<T>): [T[], T[]];
(list: string): [string, string];
};
/**
* Splits a collection into slices of the specified length.

View File

@@ -1899,6 +1899,7 @@ class Rectangle {
const b: number[][] = R.splitAt(1)([1, 2, 3]); // => [[1], [2, 3]]
const c: string[] = R.splitAt(5, "hello world"); // => ['hello', ' world']
const d: string[] = R.splitAt(-1, "foobar"); // => ['fooba', 'r']
const e: string[] = R.splitAt(-1)("foobar"); // => ['fooba', 'r']
};
() => {