Add toggle, reverse arguments for append
This commit is contained in:
@@ -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> => {
|
||||
|
||||
Reference in New Issue
Block a user