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