import { GenericMonad , InstanceMonad , MonadParameter , StaticMonad } from "../../lib/abstract/monad" ; import { Either } from "../../lib/data/either" ; import { Option } from "../../lib/data/option" ; import { test } from "../../tests/harness" ; const instanceChain = < F extends InstanceMonad < F > , B > ( fn , fa ) => fa . chain ( fn ) ; const staticChain = < F , B extends GenericMonad < F > > ( f , fn , fa ) : GenericMonad < F , MonadParameter < B > > => f . chain ( fn , fa ) ; test ( "examples/abstract/monad1" , test => { test . plan ( 4 ) ; const toString = ( a ) => Option . of ( a . toString ( ) ) ; let option = new Option ( 4 ) ; let staticOption = Option ; let instanceOption = option ; test . deepEqual < Option < string > > ( option . chain ( toString ) ) ( instanceChain ( toString , option ) ) ; test . deepEqual < Option < string > > ( option . chain ( toString ) ) ( staticChain ( Option , toString , option ) ) ; test . deepEqual < Option < string > > ( option . chain ( toString ) ) ( staticOption . chain ( toString , option ) ) ; test . deepEqual < Option < string > > ( option . chain ( toString ) ) ( instanceOption . chain ( toString ) ) ; } ) ; test ( "examples/abstract/monad2" , test => { test . plan ( 4 ) ; const toString = ( a ) => Either . of ( a . toString ( ) ) ; let either = new Option ( 4 ) . toEither ( "error" ) ; let staticEither = Either ; let instanceEither = either ; test . deepEqual < Either < string , string > > ( either . chain ( toString ) ) ( instanceChain ( toString , either ) ) ; test . deepEqual < Either < string , string > > ( either . chain ( toString ) ) ( staticChain ( Either , toString , either ) ) ; test . deepEqual < Either < string , string > > ( either . chain ( toString ) ) ( staticEither . chain ( toString , either ) ) ; test . deepEqual < Either < string , string > > ( either . chain ( toString ) ) ( instanceEither . chain ( toString ) ) ; } ) ;