import type MapFn from "./Map"; import type { Fn1, Fn2, PartialApply } from "../../HKT"; import type { ValueOf } from "../../Obj/ValueOf"; import type { Eq, Lazied, Lazied$Get } from "../../helpers"; import type { HKT, Kind } from "../HKT"; /** * A type class for types that can be converted to a string. */ export type Functor = Lazied$Get>; /** * {@link Lazied} version of {@link Functor}. */ export type FunctorL = Lazied>; /** * Type class constraints for type class {@link Functor}. */ export interface TypeClass$$Functor { /** * Map a {@link Functor} through a function. * * **⚠️ Warning:** Correctness of the method is not fully checked, so be careful when implementing * this method. * * Sig: `, T, U>(f: (x: T) => U, fa: F) => F` */ Map: Fn2, F, F>; } /** * Implementations for type class {@link Functor}. */ export interface FunctorImpl {} /** * Helper type for implementing type class {@link Functor}. */ export type ImplFunctorFor> = [F, TypeClass]; /** * Get the matching entry of {@link FunctorImpl} for `F`. * @private */ type _Functor$GetMatch = ValueOf<{ [P in keyof FunctorImpl as F extends FunctorImpl[P][0] ? P : never]: FunctorImpl[P]; }>; /** * Get the constructor of `F` from {@link FunctorImpl}. */ export type Functor$GetConstruct = Eq extends true ? Functor : _Functor$GetMatch extends [infer F extends HKT, unknown] ? F : never; /** * The **unsafe** version of {@link Functor$GetConstruct} (i.e. no type checking with `F`). */ export type Functor$GetConstructW = F extends Functor ? Functor$GetConstruct : never; /** * Get the type class of `F` from {@link FunctorImpl}. */ export type Functor$GetTypeClass = _Functor$GetMatch extends [unknown, infer TypeClass] ? TypeClass : never; /** * The **unsafe** version of {@link Functor$GetTypeClass} (i.e. no type checking with `F`). */ export type Functor$GetTypeClassW = F extends Functor ? Functor$GetTypeClass : never; /*********** * Methods * ***********/ /** * Methods for `Functor`. */ export namespace Functor { /** * [Fn] Map a {@link Functor} through a function. * * Sig: `, T, U>[f: (x: T) => U](fa: F) => F` */ export type Map = PartialApply; }