Add assoc

This commit is contained in:
Jon Staab
2024-05-20 15:29:19 -07:00
parent 1160cedc0b
commit fc0cbf5728
+3 -1
View File
@@ -1,7 +1,7 @@
import {throttle} from 'throttle-debounce' import {throttle} from 'throttle-debounce'
import {bech32, utf8} from "@scure/base" import {bech32, utf8} from "@scure/base"
// Data types // Dealing with nil
export type Nil = null | undefined export type Nil = null | undefined
@@ -117,6 +117,8 @@ export const ne = <T>(v: T) => (x: T) => x !== v
export const prop = (k: string) => <T>(x: Record<string, T>) => x[k] export const prop = (k: string) => <T>(x: Record<string, T>) => x[k]
export const assoc = <K extends string, T, U>(k: K, v: T) => (o: U) => ({...o, [k as K]: v}) as U & Record<K, T>
export const hash = (s: string) => export const hash = (s: string) =>
Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString() Math.abs(s.split("").reduce((a, b) => ((a << 5) - a + b.charCodeAt(0)) | 0, 0)).toString()