public function testMap() { $inc = function ($x) { return $x + 1; }; $this->assertEquals(State::of($inc)->ap(State::of(1))->run(null), [2, null], 'Aps.'); }
public function testGet() { $this->assertEquals(State::of(2)->chain(function ($x) { return State::get()->map(function ($y) use($x) { return $x + $y; }); })->evalState(3), 5, 'Accesses state.'); }
public function testModify() { $this->assertEquals(State::of(2)->chain(function ($x) { return State::put(55)->map(function () use($x) { return $x; }); })->run(5), [2, 55], 'Mutates state.'); }
public function testModify() { $this->assertEquals(State::of(2)->chain(function ($x) { $add = function ($x) { return $x + 1; }; return State::modify($add)->map(function () use($x) { return $x; }); })->run(10), [2, 11], 'Updates state.'); }
public function testEvalState() { $this->assertEquals(State::of(2)->run(null), [2, null], 'Evaluates with a state.'); }
public function testApplicativeConstructor() { $this->assertEquals(State::of(2)->evalState(null), 2, 'Constructs an applicative.'); }
public function testRun() { $this->assertEquals(State::of(5)->run(2), [5, 2], 'Runs the computation.'); }
public function testExec() { $this->assertEquals(State::of(null)->run(2), [null, 2], 'Executes the computation.'); }
public function testChain() { $this->assertEquals(State::of(2)->chain(function () { return State::of(3); })->run('hello'), [3, 'hello'], 'Chains.'); }