-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathappend.ts
More file actions
27 lines (21 loc) · 790 Bytes
/
append.ts
File metadata and controls
27 lines (21 loc) · 790 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Copyright (c) 2020 Jozty. All rights reserved. MIT license.
import curryN from './utils/curry_n.ts';
import type { PH } from './utils/types.ts';
// @types
type Append_2<T> = (list: T[]) => T[];
type Append_1<T> = (el: T) => T[];
type Append =
& (<T>(el: T) => Append_2<T>)
& (<T>(el: PH, list: T[]) => Append_1<T>)
& (<T>(el: T, list: T[]) => T[]);
function _append<T>(el: T, list: T[]) {
return [...list, el];
}
/**
* Add the `el` to the end of `list` and returns new list without affecting original
*
* Fae.append('tests', ['write', 'more']); //=> ['write', 'more', 'tests']
* Fae.append('tests', []); //=> ['tests']
* Fae.append(['tests'], ['write', 'more']); //=> ['write', 'more', ['tests']]
*/
export const append = curryN(2, _append) as Append;