// @flow import { HKT } from './HKT' import type { HKT2 } from './HKT' import type { Semigroupoid } from './Semigroupoid' import type { Functor } from './Functor' import type { Bifunctor } from './Bifunctor' import type { Extend } from './Extend' import type { Comonad } from './Comonad' class IsTuple {} export type TupleV = [A, B]; export type Tuple = HKT2; export function inj(t: TupleV): Tuple { return ((t: any): Tuple) } export function prj(ft: Tuple): TupleV { return ((ft: any): TupleV) } export function fst(t: Tuple): A { return prj(t)[0] } export function snd(t: Tuple): B { return prj(t)[1] } export function compose(x: Tuple, y: Tuple): Tuple { return inj([fst(y), snd(x)]) } export function map(f: (a: A) => B, fa: Tuple): Tuple { const a = prj(fa) return inj([a[0], f(a[1])]) } export function bimap(f: (a: A) => B, g: (c: C) => D, fac: Tuple): Tuple { const ac = prj(fac) return inj([f(ac[0]), g(ac[1])]) } export function extend(f: (ea: Tuple) => B, ea: Tuple): Tuple { const t = prj(ea) return inj([t[0], f(ea)]) } export const extract = snd if (false) { // eslint-disable-line ({ map, compose, bimap, extend, extract }: Semigroupoid & Functor> & Bifunctor & Extend> & Comonad>) }