Skip to content

Commit

Permalink
fix Set.concat to concatenate strings as items (#1913)
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaa91 committed Nov 17, 2022
1 parent 7cf6f8e commit 908f205
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions __tests__/Set.ts
Expand Up @@ -131,6 +131,11 @@ describe('Set', () => {
expect(Set.intersect([])).toBe(Set());
});

it('concatenates strings using union', () => {
const s = Set(['one', 'two']);
expect(s.union('three').toArray()).toEqual(['one', 'two', 'three']);
});

it('iterates values', () => {
const s = Set([1, 2, 3]);
const iterator = jest.fn();
Expand Down
6 changes: 5 additions & 1 deletion src/Set.js
Expand Up @@ -104,7 +104,11 @@ export class Set extends SetCollection {
}
return this.withMutations(set => {
for (let ii = 0; ii < iters.length; ii++) {
SetCollection(iters[ii]).forEach(value => set.add(value));
if (typeof iters[ii] === 'string') {
set.add(iters[ii]);
} else {
SetCollection(iters[ii]).forEach(value => set.add(value));
}
}
});
}
Expand Down

0 comments on commit 908f205

Please sign in to comment.