import { type Equivalence, Function, Predicate } from "effect" import type * as Component from "./Component.js" export const TypeId: unique symbol = Symbol.for("effect-fc/Memoized") export type TypeId = typeof TypeId export interface Memoized

extends Memoized.Options

{ readonly [TypeId]: true } export namespace Memoized { export interface Options

{ readonly propsAreEqual?: Equivalence.Equivalence

} } export const isMemoized = (u: unknown): u is Memoized => Predicate.hasProperty(u, TypeId) export const memo = >( self: T ): T & Memoized> => Object.setPrototypeOf( { ...self, [TypeId]: true }, Object.getPrototypeOf(self), ) export const withOptions: { & Memoized>( options: Partial>> ): (self: T) => T & Memoized>( self: T, options: Partial>>, ): T } = Function.dual(2, & Memoized>( self: T, options: Partial>>, ): T => Object.setPrototypeOf( { ...self, ...options }, Object.getPrototypeOf(self), ))