Move feed utils to its own file

This commit is contained in:
Jon Staab
2024-05-03 10:30:50 -07:00
parent a343f74241
commit d4cf63e906
10 changed files with 245 additions and 143 deletions
+16 -1
View File
@@ -15,7 +15,7 @@ export const first = <T>(xs: T[], ...args: unknown[]) => xs[0]
export const last = <T>(xs: T[], ...args: unknown[]) => xs[xs.length - 1]
export const identity = <T>(x: T) => x
export const identity = <T>(x: T, ...args: unknown[]) => x
export const inc = (x: number | Nil) => (x || 0) + 1
@@ -132,6 +132,21 @@ export const ensureNumber = (x: number | string) => parseFloat(x as string)
export const flatten = <T>(xs: T[][]) => xs.flatMap(identity)
export const partition = <T>(f: (x: T) => boolean, xs: T[]) => {
const a: T[] = []
const b: T[] = []
for (const x of xs) {
if (f(x)) {
a.push(x)
} else {
b.push(x)
}
}
return [a, b]
}
export const uniq = <T>(xs: T[]) => Array.from(new Set(xs))
export const uniqBy = <T>(f: (x: T) => any, xs: T[]) => {