- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25
filter over Map #136
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
base: develop
Are you sure you want to change the base?
filter over Map #136
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|  | @@ -10,10 +10,18 @@ export function filter<A, P extends A>( | |||||||||||||
| <B extends A>(list: readonly B[]): P[]; | ||||||||||||||
| 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. Github doesn't let you add suggests to unchanged code, but you need to add type support for  // filter(() => narrow)
export function filter<A, P extends A>(
  pred: (val: A) => val is P,
): {
  // filter(() => narrow)(map)
  <K, B extends A>(map: Map<K, B>): Map<K, P>;
  // if we put `Record<string, A>` first, it will actually pic`A[]` as well
  // so it needs to go first
  // filter(() => narrow)(list)
  <B extends A>(list: readonly B[]): P[];
  // filter(() => narrow)(dict)
  <B extends A>(dict: Record<string, B>): Record<string, P>;
  // but we also want `A[]` to be the default when doing `pipe(filter(fn))`, so it also needs to be last
  // filter(() => narrow)(list | dict)
  <B extends A>(list: readonly B[]): P[];
}; | ||||||||||||||
| }; | ||||||||||||||
|  | ||||||||||||||
| // filter(() => boolean) | ||||||||||||||
| // filter(() => boolean)(list | dict) | ||||||||||||||
| 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. 
        Suggested change
       
 | ||||||||||||||
| export function filter<T>( | ||||||||||||||
| pred: (value: T) => boolean, | ||||||||||||||
| ): <P extends T, C extends readonly P[] | Record<string, P>>(collection: C) => C; | ||||||||||||||
| ): { | ||||||||||||||
| <K>(map: Map<K, T>): Map<K, T>; | ||||||||||||||
| <P extends T, C extends readonly P[] | Record<string, P>>(collection: C): C; | ||||||||||||||
| 
      Comment on lines
    
      +17
     to 
      +18
    
   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. 
        Suggested change
       
 | ||||||||||||||
| }; | ||||||||||||||
|  | ||||||||||||||
| // filter(() => narrow, map) | ||||||||||||||
| export function filter<K, T, P extends T>(pred: (val: T) => val is P, map: Map<K, T>): Map<K, P>; | ||||||||||||||
| // filter(() => boolean, map) | ||||||||||||||
| export function filter<K, T>(pred: (val: T) => boolean, map: Map<K, T>): Map<K, T>; | ||||||||||||||
|  | ||||||||||||||
| // filter(() => narrow, list) - readonly T[] falls into Record<string T> for some reason, so list needs to come first | ||||||||||||||
| export function filter<T, P extends T>(pred: (val: T) => val is P, list: readonly T[]): P[]; | ||||||||||||||
|  | ||||||||||||||
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.
First, these tests are for
// filter(() => narrow, map)Second, you need to be far more exhaustive with your test additions. This file has test coverage for all curry varieties and argument type overloads. You added support for a new argument type, so you need to add tests for each curry call variation