Skip to content

Commit ddacdf7

Browse files
feat(maps): Add append
Add Maps.append to match other modules. Add TypeDoc comments for all append functions.
1 parent 887b1f9 commit ddacdf7

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

src/arrays.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,17 @@ export function collect<T, U>(a: any, b?: any): any {
100100
return partial ? exec : exec(a)
101101
}
102102

103+
/**
104+
* Wraps the two given arrays as a single concatenated array.
105+
* @param second The second array.
106+
* @param first The first array.
107+
*/
103108
export function append<T>(second: T[]): (first: T[]) => T[]
109+
/**
110+
* Wraps the two given arrays as a single concatenated array.
111+
* @param first The first array.
112+
* @param second The second array.
113+
*/
104114
export function append<T>(first: T[], second: T[]): T[]
105115
export function append<T>(a: any, b?: any): any {
106116
const partial = b === undefined

src/iterables.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ export function collect<T, U>(a: any, b?: any): any {
109109
/**
110110
* Wraps the two given iterables as a single concatenated iterable.
111111
* @param second The second iterable.
112+
* @param first The first iterable.
112113
*/
113114
export function append<T>(second: Iterable<T>): (first: Iterable<T>) => Iterable<T>
114115
/**

src/maps.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@ export function choose<Key, T, U>(a: any, b?: any): any {
122122
return partial ? exec : exec(a)
123123
}
124124

125+
/**
126+
* Wraps the two given maps as a single concatenated map.
127+
* @param second The second map.
128+
* @param first The first map.
129+
*/
130+
export function append<Key, T>(second: Map<Key, T>): (first: Map<Key, T>) => Map<Key, T>
131+
/**
132+
* Wraps the two given maps as a single concatenated map.
133+
* @param first The first map.
134+
* @param second The second map.
135+
*/
136+
export function append<Key, T>(first: Map<Key, T>, second: Map<Key, T>): Map<Key, T>
137+
export function append<Key, T>(a: any, b?: any): any {
138+
const partial = b === undefined
139+
const second: Map<Key, T> = partial ? a : b
140+
function exec(first: Map<Key, T>): Map<Key, T> {
141+
return new Map<Key, T>(Iterables.append(first, second))
142+
}
143+
return partial ? exec : exec(a)
144+
}
145+
125146
export function get<Key, T>(key: Key): (source: Map<Key, T>) => T
126147
export function get<Key, T>(source: Map<Key, T>, key: Key): T
127148
export function get<Key, T>(a: any, b?: any): any {

src/sets.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,17 @@ export function collect<T, U>(a: any, b?: any): any {
120120
return partial ? exec : exec(a)
121121
}
122122

123+
/**
124+
* Wraps the two given sets as a single concatenated set.
125+
* @param second The second set.
126+
* @param first The first set.
127+
*/
123128
export function append<T>(second: Set<T>): (first: Set<T>) => Set<T>
129+
/**
130+
* Wraps the two given sets as a single concatenated set.
131+
* @param first The first set.
132+
* @param second The second set.
133+
*/
124134
export function append<T>(first: Set<T>, second: Set<T>): Set<T>
125135
export function append<T>(a: any, b?: any): any {
126136
const partial = b === undefined

test/maps.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ describe('choose', () => {
7676
})
7777
})
7878

79+
describe('append', () => {
80+
test('immediate', () => {
81+
expect(Maps.append(new Map([['a', 1], ['b', 2]]), new Map([['b', 2], ['c', 3]]))).toEqual(
82+
new Map([['a', 1], ['b', 2], ['c', 3]])
83+
)
84+
})
85+
test('piped', () => {
86+
expect(
87+
pipe(
88+
new Map([['a', 1], ['b', 2], ['c', 3]]),
89+
Maps.append(new Map([['a', 1], ['b', 2], ['c', 3]]))
90+
)
91+
).toEqual(new Map([['a', 1], ['b', 2], ['c', 3]]))
92+
})
93+
})
94+
7995
describe('get', () => {
8096
test('immediate', () => {
8197
expect(Maps.get(new Map([['a', 1], ['b', 2]]), 'b')).toEqual(2)

0 commit comments

Comments
 (0)