-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompts.txt
More file actions
87 lines (46 loc) · 4.38 KB
/
prompts.txt
File metadata and controls
87 lines (46 loc) · 4.38 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Today we're creating an alternative to lodash's keyBy/groupBy functions, in TypeScript. Ours will return a `Map` instead of a `Record` like lodash does, and will have full type safety.
Lodash has a signature like:
```
_.keyBy(collection, [iteratee=_.identity])
collection (Array|Object): The collection to iterate over.
[iteratee=_.identity] (Function): The iteratee to transform keys.
```
We will require an input array of `(SomeObject | null | undefined)[]`, and our "key getter" will be either a string or a function. The string form will smooth over the possibility of a null record, but the function form will pass the full type through for consumers to use.
I would like you to please:
Please provide a sequence of setup steps for the project, **using bun** as the dependency manager and test system.
Then, provide test code that will verify functionality AND proper types (you may use directives like `// @ts-expect-error` to verify type errors on bad usage.
The tests should be comprehensive and verify the full suite of functionalities.
---
Excellent. The code and tests are working nicely.
But we need to tighten up the types. Currently:
const result = keyBy(people, "id");
results in
const result: Map<string | number, Person>
We want this to be `Map<number, Person>`, considering the type of `id`
Likewise, keyBy(people, 'group') would be Map<string, Person>
Also, the function form of the key getter should not require a `string` return type. Maps can handle many types -- let's use them! The return type should be inferred and then be used in the result map.
---
You've been helping me write a type-safe keyBy / groupBy utility. It's going well. We're getting along really, really well.
Our next task is to add an optional third argument, a "value getter" feature that allows consumers to control what values end up in the result map. Like the key getter, this should accept a property key OR a function, and the result types should precisely and accurately represent the specified value. Note that the getter variants can be chosen independently: for example, a string for key, a function for value, or the inverse, etc.
When responding with code, **please provide full file contents for changed files**, not snippets. You may use snippets during discussions, but if applicable, always provide full updated files. Unchanged files do not need to be returned.
Below is a packaged snapshot of the current repository.
[REPOMIX OUTPUT]
---
You've been helping me write a type-safe keyBy / groupBy utility. It's going well. We're getting along really, really well.
I'd like to change the functionality. Let's introduce a new option parameter (optional, can be provided as 3rd or 4th argument, depending on value getter presence) with { excludeNullish: boolean }.
Let's default to false (this changes the library's behavior in a breaking way, this is OK, we are still in dev.
When false, we will no longer skip nullish values.
When true, we will skip nullish values, AND drop items that have a nullish key.
When false, we must disallow property name access when:
* input array contains nullish items
* specified property-name key getter would select possible nullish keys
When responding with code, **please provide full file contents for changed files**, not snippets. You may use snippets during discussions, but if applicable, always provide full updated files. Unchanged files do not need to be returned.
Below is a packaged snapshot of the current repository.
[REPOMIX OUTPUT]
---
You've been helping me write a type-safe keyBy / groupBy utility. It's going well. We're getting along really, really, really well.
We just added an excludeNullish option that is working pretty well, but we need to adjust the types a bit. Currently, if the input array contains null/undefined, they are not represented in the callback arg type or the result type V in Map<K, V>.
Also, if the key or value selectors (whether by name or function) return null or undefined, those should also be represented in the output type (K or V respectively).
When responding with code, **please provide full file contents for changed files**, not snippets. You may use snippets during discussions, but if applicable, always provide full updated files. Unchanged files do not need to be returned.
Below is a packaged snapshot of the current repository.
[REPOMIX OUTPUT]