export const HashMapPatchSym = Symbol.for("@Differ.HashMap.Patch") export type HashMapPatchSym = typeof HashMapPatchSym export const HashMapPatchKeySym = Symbol.for("@Differ.HashMap.Patch.Key") export type HashMapPatchKeySym = typeof HashMapPatchKeySym export const HashMapPatchValueSym = Symbol.for("@Differ.HashMap.Patch.Value") export type HashMapPatchValueSym = typeof HashMapPatchValueSym export const HashMapPatchPatchSym = Symbol.for("@Differ.HashMap.Patch.Patch") export type HashMapPatchPatchSym = typeof HashMapPatchPatchSym /** * A patch which describes updates to a map of keys and values. * * @tsplus type Differ.HashMap.Patch */ export interface HashMapPatch { readonly [HashMapPatchSym]: HashMapPatchSym readonly [HashMapPatchKeySym]: (_: Key) => Key readonly [HashMapPatchValueSym]: (_: Value) => Value readonly [HashMapPatchPatchSym]: (_: Patch) => Patch } /** * @tsplus type Differ.HashMap.Patch.Ops */ export interface HashMapPatchOps { readonly $: HashMapPatchAspects } /** * @tsplus static Differ.Ops HashMap */ export const HashMapPatch: HashMapPatchOps = { $: {} } /** * @tsplus type Differ.HashMap.Patch.Aspects */ export interface HashMapPatchAspects {} /** * @tsplus unify Differ.HashMap.Patch */ export function unifyHashMapPatch>(self: X): HashMapPatch< [X] extends [{ [HashMapPatchKeySym]: (_: infer Key) => infer Key }] ? Key : never, [X] extends [{ [HashMapPatchValueSym]: (_: infer Value) => infer Value }] ? Value : never, [X] extends [{ [HashMapPatchPatchSym]: (_: infer Patch) => infer Patch }] ? Patch : never > { return self } export abstract class BaseHashMapPatch implements HashMapPatch { readonly [HashMapPatchSym]: HashMapPatchSym = HashMapPatchSym readonly [HashMapPatchKeySym]!: (_: Key) => Key readonly [HashMapPatchValueSym]!: (_: Value) => Value readonly [HashMapPatchPatchSym]!: (_: Patch) => Patch } export class AddHashMapPatch extends BaseHashMapPatch { readonly _tag = "Add" constructor(readonly key: Key, readonly value: Value) { super() } } export class RemoveHashMapPatch extends BaseHashMapPatch { readonly _tag = "Remove" constructor(readonly key: Key) { super() } } export class UpdateHashMapPatch extends BaseHashMapPatch { readonly _tag = "Update" constructor(readonly key: Key, readonly patch: Patch) { super() } } export class EmptyHashMapPatch extends BaseHashMapPatch { readonly _tag = "Empty" } export class AndThenHashMapPatch extends BaseHashMapPatch { readonly _tag = "AndThen" constructor( readonly first: HashMapPatch, readonly second: HashMapPatch ) { super() } } export type HashMapPatchInstruction = | AddHashMapPatch | RemoveHashMapPatch | UpdateHashMapPatch | EmptyHashMapPatch | AndThenHashMapPatch /** * @tsplus macro identity */ export function hashMapPatchInstruction( self: HashMapPatch ): HashMapPatchInstruction { // @ts-expect-error return self }