-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/improve group by key types #143
Merged
TkDodo
merged 16 commits into
remeda:master
from
TkDodo:feature/improve-groupBy-key-types
Nov 11, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
94c6c1e
Merge pull request #1 from remeda/master
TkDodo 4e07d67
Merge pull request #2 from remeda/master
TkDodo f15eefc
Merge pull request #3 from remeda/master
TkDodo 7d7e85c
Merge branch 'remeda:master' into master
TkDodo 33aa1b4
Merge branch 'remeda:master' into master
TkDodo 5a69bd4
Merge branch 'remeda:master' into master
TkDodo 893b537
Merge branch 'remeda:master' into master
TkDodo 60a5770
Merge branch 'remeda:master' into master
TkDodo 6bed375
improve groupBy key typings
TkDodo 0b308af
Merge branch 'remeda:master' into master
TkDodo 6d07266
Merge branch 'master' into feature/improve-groupBy-key-types
TkDodo 77617b5
update typescript version
TkDodo 2ef925c
make returnType of groupBy partial
TkDodo 70438f6
add an extra test for unknown properties
TkDodo 83e04aa
use built-in PropertyKey instead of our own type
TkDodo b66c416
fix types for indexed version
TkDodo File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,14 +13,14 @@ import { NonEmptyArray, PredIndexedOptional, PredIndexed } from './_types'; | |
* @indexed | ||
* @category Array | ||
*/ | ||
export function groupBy<T>( | ||
items: readonly T[], | ||
fn: (item: T) => PropertyKey | ||
): Record<PropertyKey, NonEmptyArray<T>>; | ||
export function groupBy<Item, Key extends PropertyKey>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but I think we can replace this definition one day:
with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done: 83e04aa |
||
items: readonly Item[], | ||
fn: (item: Item) => Key | ||
): Partial<Record<Key, NonEmptyArray<Item>>>; | ||
|
||
export function groupBy<T>( | ||
fn: (item: T) => PropertyKey | ||
): (array: readonly T[]) => Record<PropertyKey, NonEmptyArray<T>>; | ||
export function groupBy<Item, Key extends PropertyKey>( | ||
fn: (item: Item) => Key | ||
): (array: readonly Item[]) => Partial<Record<Key, NonEmptyArray<Item>>>; | ||
|
||
/** | ||
* Splits a collection into sets, grouped by the result of running each value through `fn`. | ||
|
@@ -54,13 +54,13 @@ const _groupBy = (indexed: boolean) => <T>( | |
}; | ||
|
||
export namespace groupBy { | ||
export function indexed<T, K>( | ||
array: readonly T[], | ||
fn: PredIndexed<T, PropertyKey> | ||
): Record<string, NonEmptyArray<T>>; | ||
export function indexed<T, K>( | ||
fn: PredIndexed<T, PropertyKey> | ||
): (array: readonly T[]) => Record<string, NonEmptyArray<T>>; | ||
export function indexed<Item, Key extends PropertyKey>( | ||
array: readonly Item[], | ||
fn: PredIndexed<Item, Key> | ||
): Partial<Record<Key, NonEmptyArray<Item>>>; | ||
export function indexed<Item, Key extends PropertyKey>( | ||
fn: PredIndexed<Item, Key> | ||
): (array: readonly Item[]) => Partial<Record<Key, NonEmptyArray<Item>>>; | ||
export function indexed() { | ||
return purry(_groupBy(true), arguments); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
70438f6