export interface TupleTypeRef { < F , S > ( fst , snd ) : Tuple < F , S > ; /** Applies two functions over a single value and constructs a tuple from the results */ fanout < F , S , T > ( f , g , value ) : Tuple < F , S > ; fanout < F , S , T > ( f , g ) : ( value : T ) => Tuple < F , S > ; fanout < F , T > ( f ) : < S > ( g : ( value : T ) => S ) => ( value : T ) => Tuple < F , S > ; /** Constructs a tuple from an array with two elements */ fromArray < F , S > ( [ fst , snd ] ) : Tuple < F , S > ; } export const TUPLE_URI = 'Tuple' ; export type TUPLE_URI = typeof TUPLE_URI ; declare module './pointfree/hkt' { export interface URI2HKT < Types extends any [ ] > { [ TUPLE_URI ] : Tuple < Types [ 1 ] , Types [ 0 ] > ; } } export interface Tuple < F , S > extends Iterable < F | S > , ArrayLike < F | S > { 0 : F ; 1 : S ; readonly _URI : TUPLE_URI ; readonly _A : [ S , F ] ; [ index ] : F | S ; length : 2 ; toJSON ( ) : [ F , S ] ; inspect ( ) : string ; toString ( ) : string ; /** Returns the first value of `this` */ fst ( ) : F ; /** Returns the second value of `this` */ snd ( ) : S ; /** Compares the values inside `this` and another tuple */ equals ( other ) : boolean ; /** Transforms the two values inside `this` with two mapper functions */ bimap < F2 , S2 > ( f , g ) : Tuple < F2 , S2 > ; /** Applies a function to the first value of `this` */ mapFirst < F2 > ( f ) : Tuple < F2 , S > ; /** Applies a function to the second value of `this` */ map < S2 > ( f ) : Tuple < F , S2 > ; /** A somewhat arbitrary implementation of Foldable for Tuple, the reducer will be passed the initial value and the second value inside `this` as arguments */ reduce < T > ( reducer , initialValue ) : T ; /** Returns an array with 2 elements - the values inside `this` */ toArray ( ) : [ F , S ] ; /** Swaps the values inside `this` */ swap ( ) : Tuple < S , F > ; /** Applies the second value of a tuple to the second value of `this` */ ap < T , S2 > ( f ) : Tuple < F , S2 > ; /** Tests whether both elements in the tuple pass the test implemented by the provided function */ every ( pred ) : boolean ; /** Tests whether at least one element in the tuple passes the test implemented by the provided function */ some ( pred ) : boolean ; 'fantasy-land/equals' ( other ) : boolean ; 'fantasy-land/bimap' < F2 , S2 > ( f , g ) : Tuple < F2 , S2 > ; 'fantasy-land/map' < S2 > ( f ) : Tuple < F , S2 > ; 'fantasy-land/reduce' < T > ( reducer , initialValue ) : T ; 'fantasy-land/ap' < T , S2 > ( f ) : Tuple < F , S2 > ; } class TupleImpl < F , S > implements Tuple < F , S > { 0 : F ; 1 : S ; [ index ] : F | S ; length : 2 = 2 ; constructor ( private first , private second ) { this [ 0 ] = first ; this [ 1 ] = second ; } readonly _URI ! : TUPLE_URI ; readonly _A ! : [ S , F ] ; * [ Symbol . iterator ] ( ) { yield this . first ; yield this . second ; } toJSON ( ) { return this . toArray ( ) ; } inspect ( ) { return `Tuple(${ JSON . stringify ( this . first ) }, ${ JSON . stringify ( this . second ) })` ; } toString ( ) { return this . inspect ( ) ; } fst ( ) { return this . first ; } snd ( ) { return this . second ; } equals ( other ) { return this . first === other . fst ( ) && this . second === other . snd ( ) ; } bimap < F2 , S2 > ( f , g ) { return Tuple ( f ( this . first ) , g ( this . second ) ) ; } mapFirst < F2 > ( f ) { return Tuple ( f ( this . first ) , this . second ) ; } map < S2 > ( f ) { return Tuple ( this . first , f ( this . second ) ) ; } reduce < T > ( reducer , initialValue ) { return reducer ( initialValue , this . second ) ; } toArray ( ) { return [ this . first , this . second ] ; } swap ( ) { return Tuple ( this . second , this . first ) ; } ap < T , S2 > ( f ) { return Tuple ( this . first , f . snd ( ) ( this . second ) ) ; } every ( pred ) { return pred ( this . first ) && pred ( this . second ) ; } some ( pred ) { return pred ( this . first ) || pred ( this . second ) ; } 'fantasy-land/equals' ( other ) { return this . equals ( other ) ; } 'fantasy-land/bimap' < F2 , S2 > ( f , g ) { return this . bimap ( f , g ) ; } 'fantasy-land/map' < S2 > ( f ) { return this . map ( f ) ; } 'fantasy-land/reduce' < T > ( reducer , initialValue ) { return this . reduce ( reducer , initialValue ) ; } 'fantasy-land/ap' < T , S2 > ( f ) { return this . ap ( f ) ; } } export const Tuple = Object . assign ( < F , S > ( fst , snd ) => new TupleImpl ( fst , snd ) , { fromArray : < F , S > ( [ fst , snd ] ) : Tuple < F , S > => { return Tuple ( fst , snd ) ; } , fanout : < F , S , T > ( ... args ) : any => { const [ f , g , value ] = args ; switch ( args . length ) { case 3 : return Tuple ( f ( value ! ) , g ! ( value ! ) ) ; case 2 : return ( value ) => Tuple . fanout ( f , g ! , value ) ; default : return < S > ( g ) => ( value ) => Tuple . fanout ( f , g , value ) ; } } } ) ; TupleImpl . prototype . constructor = Tuple as any ;