UNPKG

rivo

Version:

🤖 The ultimate library you need for composable type-level programming in TypeScript, powered by HKT.

26 lines (23 loc) • 942 B
import type { Semigroup, Semigroup$GetConstruct, Semigroup$GetTypeClass } from "."; import type { Args, Call2W, Cons, Fn } from "../../HKT"; import type { IsAny } from "../../helpers"; /** * Concat two {@link Semigroup} instances. * * Sig: `(s1: Semigroup, s2: Semigroup) => Semigroup` * * Type safety is **not guaranteed** if `S1` and `S2` are not of the same construct. */ export type Concat<S1 extends Semigroup, S2 extends Semigroup> = [IsAny<S1>, IsAny<S2>] extends [true, true] ? Semigroup : IsAny<S1> extends true ? Semigroup$GetConstruct<S2> : IsAny<S2> extends true ? Semigroup$GetConstruct<S1> : Call2W<Semigroup$GetTypeClass<S1>["Concat"], S1, S2>; /** * [Fn] Concat two {@link Semigroup} instances. * * Sig: `<S extends Cons<Semigroup>>(s1: S, s2: S) => S` */ export default interface ConcatFn<S extends Cons<Semigroup>> extends Fn<[S, S], S> { def: ([s1, s2]: Args<this>) => Concat<typeof s1, typeof s2>; }