Skip to content

Commit

Permalink
change sift return type from T to NonNullable<T> (#99)
Browse files Browse the repository at this point in the history
* change sift return type from T to NonNullable<T>

* bump patch version

* try get types to pass
  • Loading branch information
sodiray authored Oct 14, 2022
1 parent 7a8a959 commit fad2b94
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "radash",
"version": "7.1.0",
"version": "7.1.1",
"description": "Functional utility library - modern, simple, typed, powerful",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
17 changes: 12 additions & 5 deletions src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* the group ids the given getGroupId function produced and the value is an array of
* each item in that group.
*/
export const group = <T, Key extends string | number | symbol>(
export const group = <T, Key extends string | number | symbol>(
array: readonly T[],
getGroupId: (item: T) => Key
) => {
Expand All @@ -21,7 +21,10 @@
*
* Ex. const greatest = () => boil(numbers, (a, b) => a > b)
*/
export const boil = <T>(array: readonly T[], compareFunc: (a: T, b: T) => T) => {
export const boil = <T>(
array: readonly T[],
compareFunc: (a: T, b: T) => T
) => {
if (!array || (array.length ?? 0) === 0) return null
return array.reduce(compareFunc)
}
Expand Down Expand Up @@ -310,7 +313,11 @@ export const fork = <T>(
* and replace items matched by the matcher func in the
* first place.
*/
export const merge = <T>(root: readonly T[], others: readonly T[], matcher: (item: T) => any) => {
export const merge = <T>(
root: readonly T[],
others: readonly T[],
matcher: (item: T) => any
) => {
if (!others && !root) return []
if (!others) return root
if (!root) return []
Expand Down Expand Up @@ -352,8 +359,8 @@ export const replaceOrAppend = <T>(
* Given a list returns a new list with
* only truthy values
*/
export const sift = <T>(list: readonly T[]) => {
return list?.filter(x => !!x) ?? []
export const sift = <T>(list: readonly T[]): NonNullable<T>[] => {
return (list?.filter(x => !!x) as NonNullable<T>[]) ?? []
}

/**
Expand Down

0 comments on commit fad2b94

Please sign in to comment.