Skip to content

Commit

Permalink
feat : FilterNullish method created
Browse files Browse the repository at this point in the history
  • Loading branch information
kakasoo committed Feb 4, 2024
1 parent 983fc13 commit a8ffb33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
12 changes: 2 additions & 10 deletions src/prototypes/array.prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,8 @@ export const ArrayPrototype = {
filter<Container extends ReadonlyOrNot<any[]>, Target = any>(
container: Container,
predicate: ArrayType.TypePredicate<Container, Target>,
): Equal<Target, unknown> extends true
? boolean
: Equal<Target, any> extends true
? boolean
: ArrayType.Filter<Container, Target> {
return container.filter(predicate as any) as Equal<Target, unknown> extends true
? boolean
: Equal<Target, any> extends true
? boolean
: ArrayType.Filter<Container, Target>;
): ArrayType.Filter<Container, Target> {
return container.filter(predicate as any) as ArrayType.Filter<Container, Target>;
},

/**
Expand Down
4 changes: 2 additions & 2 deletions src/types/array.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { Equal, ObjectType } from './object.type';
import { Primitive, ReadonlyOrNot } from './primitive.type';

export namespace ArrayType {
export type TypePredicate<Container extends ReadonlyOrNot<any[]>, Target extends any = any> = {
export type TypePredicate<Container extends ReadonlyOrNot<any[]>, Target> = {
<Index extends number, __Target extends Target = Target>(
value: ArrayType.At<Container, Index>,
value?: ArrayType.At<Container, Index>,
index?: Index,
array?: Container,
): value is Target;
Expand Down

0 comments on commit a8ffb33

Please sign in to comment.