Add toggle, reverse arguments for append

This commit is contained in:
Jon Staab
2024-06-26 09:22:11 -07:00
parent e7967b72d5
commit a277c107bb
+3 -1
View File
@@ -93,7 +93,7 @@ export const sleep = (t: number) => new Promise(resolve => setTimeout(resolve, t
export const concat = <T>(...xs: (T | Nil)[][]) => xs.flatMap(x => x || [])
export const append = <T>(xs: (T | Nil)[], x: T) => concat(xs, [x])
export const append = <T>(x: T, xs: (T | Nil)[]) => concat(xs, [x])
export const union = <T>(a: T[], b: T[]) => uniq([...a, ...b])
@@ -113,6 +113,8 @@ export const remove = <T>(a: T, b: T[]) => b.filter(x => x !== a)
export const without = <T>(a: T[], b: T[]) => b.filter(x => !a.includes(x))
export const toggle = <T>(x: T, xs: T[]) => xs.includes(x) ? remove(x, xs) : append(x, xs)
export const clamp = ([min, max]: [number, number], n: number) => Math.min(max, Math.max(min, n))
export const tryCatch = async <T>(f: () => Promise<T | void> | T | void, onError?: (e: Error) => void): Promise<T | void> => {