import "mocha" ; import { assert } from "chai" ; import { functor } from "../src/functor" ; import { Freer , Pure , Bind , liftF } from "../src/freer" ; import { go } from "../src/monad" ; describe ( "Freer" , ( ) => { describe ( "implementing State" , ( ) => { class State < S , A > { constructor ( public state ) { } } const get = new State ( s => [ s , s ] ) ; const put = < S > ( s ) => new State ( _ => [ undefined , s ] ) ; const getF = liftF ( get ) ; const putF = < S > ( s ) => liftF ( put ( s ) ) ; function runFState < S , A > ( t , s ) { return t . match < [ A , S ] > ( { pure : a => [ a , s ] , bind : ( m , q ) => { const [ x , s2 ] = m . state ( s ) ; return runFState ( q ( x ) , s2 ) ; } } ) ; } it ( "works" , ( ) => { const testState = go ( function * ( ) { yield putF ( 10 ) ; const x = yield getF ; return x ; } ) ; assert . deepEqual ( runFState ( testState , 0 ) , [ 10 , 10 ] ) ; } ) ; } ) ; } ) ;