import { Semigroup , combine } from "./semigroup" ; export interface Monoid < A > extends Semigroup < A > { identity : ( ) => A ; } export interface MonoidDictionary < M extends Monoid < M > > { identity : ( ) => M ; } export interface MonoidConstructor < A , M extends Monoid < M > > { create ( a ) : M ; identity : ( ) => M ; } export type AnyMonoid < A > = string | Array < any > | Monoid < A > ; export function identity ( m ) ; export function identity ( m ) ; export function identity < M extends Monoid < M > > ( m ) ; export function identity < M extends Monoid < M > > ( m ) { if ( m === Array ) { return [ ] ; } else if ( m === String ) { return "" ; } else { return m . identity ( ) ; } }