import { foldlArray1 , arrayFlatten } from "./utils" ; export interface Semigroup < T > { combine : ( a : T ) => T ; } export type AnySemigroup < A > = string | Array < any > | Semigroup < A > ; function combineTwo < A extends Semigroup < A > > ( a , b ) { return a . combine ( b ) ; } export function combine < A extends AnySemigroup < A > > ( ... a ) ; export function combine < A extends AnySemigroup < A > > ( ... a ) { if ( Array . isArray ( a [ 0 ] ) ) { return arrayFlatten ( a ) ; } else if ( typeof a [ 0 ] === "string" ) { return a . join ( "" ) ; } else { return foldlArray1 < A > ( combineTwo , a ) ; } }