/** * The `Semialign` type class represents functors supporting a zip operation that takes the * union of non-uniform shapes. * * `Semialign` instances are required to satisfy the following laws: * * 1. `F.align(fa, fa) = F.map(fa, (a) => both(a, a))` * 2. `F.align(F.map(fa, f), F.map(fb, g)) = F.map(F.align(fa, fb), (t) => These.bimap(t, f, g))` * 3. `F.alignWith(fa, fb, f) = F.map(F.align(fa, fb), f)` * 4. `F.align(fa, F.align(fb, fc)) = F.map(F.align(F.align(fa, fb), fc), These.assoc)` * * Where `These.assoc` implements the associativity law of `These` and has the following type signature: * `function assoc(fa: These>): These, C>` * * Adapted from http://hackage.haskell.org/package/these-0.8/docs/Data-Align.html * * @since 0.1.0 */ import { Functor, Functor1, Functor2, Functor2C, Functor3 } from 'fp-ts/lib/Functor' import { HKT, Kind, Kind2, Kind3, URIS, URIS2, URIS3 } from 'fp-ts/lib/HKT' import { These } from 'fp-ts/lib/These' /** * @since 0.1.0 */ export interface Semialign extends Functor { readonly align: (fa: HKT, fb: HKT) => HKT> readonly alignWith: (fa: HKT, fb: HKT, f: (x: These) => C) => HKT } /** * @since 0.1.0 */ export interface Semialign1 extends Functor1 { readonly align: (fa: Kind, fb: Kind) => Kind> readonly alignWith: (fa: Kind, fb: Kind, f: (x: These) => C) => Kind } /** * @since 0.1.0 */ export interface Semialign2 extends Functor2 { readonly align: (fa: Kind2, fb: Kind2) => Kind2> readonly alignWith: (fa: Kind2, fb: Kind2, f: (x: These) => C) => Kind2 } /** * @since 0.1.0 */ export interface Semialign2C extends Functor2C { readonly align: (fa: Kind2, fb: Kind2) => Kind2> readonly alignWith: (fa: Kind2, fb: Kind2, f: (x: These) => C) => Kind2 } /** * @since 0.1.0 */ export interface Semialign3 extends Functor3 { readonly align: (fa: Kind3, fb: Kind3) => Kind3> readonly alignWith: ( fa: Kind3, fb: Kind3, f: (x: These) => C ) => Kind3 }