-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…' - Makes type more flexible. - Updated 'group', 'groupBy', 'intercalate', and 'intersperse' types, to allow 'Slice' type. - Updated tests for, the above, and 'concatMap'.
- Loading branch information
Showing
11 changed files
with
93 additions
and
62 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
import {Slice} from "../types"; | ||
import {of} from "../object"; | ||
|
||
export const | ||
|
||
/** | ||
* Takes an element and a list and `intersperses' that element between the | ||
* elements of the list. | ||
*/ | ||
intersperse = <T, TS extends T[]>(between: T, xs: TS): T[] => { | ||
if (!xs || !xs.length) { | ||
return []; | ||
} | ||
const limit = xs.length, | ||
intersperse = <T = string | any>(between: T, xs: Slice<T>): Slice<T> => { | ||
const limit = xs.length; | ||
if (!limit) return of(xs); | ||
const isArrayXs = Array.isArray(xs), | ||
lastInd = limit - 1; | ||
let i = 0; | ||
const out = [] as T[]; | ||
for (; i < limit; i += 1) { | ||
let out = of(xs); | ||
for (let i = 0; i < limit; i += 1) { | ||
if (i === lastInd) { | ||
out.push(xs[i] as T); | ||
if (isArrayXs) (out as T[]).push(xs[i]); | ||
else out = out.concat(xs[i]); | ||
} else { | ||
out.push(xs[i] as T, between); | ||
if (isArrayXs) (out as T[]).push(xs[i], between); | ||
else out = out.concat(xs[i], between as unknown as any); | ||
} | ||
} | ||
return out; | ||
}, | ||
|
||
$intersperse = <T, TS extends T[]>(between: T) => | ||
(xs: TS): T[] => intersperse(between, xs) | ||
$intersperse = <T>(between: T) => | ||
(xs: Slice<T>): Slice<T> => intersperse(between, xs) | ||
|
||
; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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