1 | export function getSetLikeFromInsertLike(insert, isLike, toFn, fromFn, equals) {
|
2 | function getIndex(match) {
|
3 | if (insert.indexOf) {
|
4 | return insert.indexOf(match);
|
5 | }
|
6 | let index = -1;
|
7 | for (const value of insert) {
|
8 | index += 1;
|
9 | if (equals(value, match)) {
|
10 | return index;
|
11 | }
|
12 | }
|
13 | return -1;
|
14 | }
|
15 | return {
|
16 | get size() {
|
17 | return insert.length;
|
18 | },
|
19 | has(value) {
|
20 | return getIndex(fromFn(value)) > -1;
|
21 | },
|
22 | add(value) {
|
23 | insert.push([fromFn(value)]);
|
24 | },
|
25 | delete(value) {
|
26 | const index = getIndex(fromFn(value));
|
27 | if (index === -1) {
|
28 | return;
|
29 | }
|
30 | insert.delete(index, 1);
|
31 | },
|
32 | *[Symbol.iterator]() {
|
33 | for (const value of insert) {
|
34 | if (isLike(value)) {
|
35 | yield toFn(value);
|
36 | }
|
37 | }
|
38 | }
|
39 | };
|
40 | }
|
41 |
|
\ | No newline at end of file |