Widmogrod\Helpful\FunctorLaws::test PHP Method

test() public static method

Generic test to verify if a type obey the functor laws.
public static test ( callable $assertEqual, callable $f, callable $g, Widmogrod\FantasyLand\Functor $x )
$assertEqual callable Asserting function (Functor $f1, Functor $f2, $message)
$f callable (a -> b)
$g callable (a -> b)
$x Widmogrod\FantasyLand\Functor f a
    public static function test(callable $assertEqual, callable $f, callable $g, Functor $x)
    {
        // identity: fmap id  ==  id
        $assertEqual(f\map(f\identity, $x), $x, 'identity');
        // composition: fmap (f . g)  ==  fmap f . fmap g
        $assertEqual(f\map(f\compose($f, $g), $x), call_user_func(f\compose(f\map($f), f\map($g)), $x), 'composition');
    }

Usage Example

 /**
  * @dataProvider provideFunctorTestData
  */
 public function test_it_should_obey_functor_laws(callable $f, callable $g, Functor $x)
 {
     FunctorLaws::test(f\curryN(3, [$this, 'assertEquals']), $f, $g, $x);
 }
All Usage Examples Of Widmogrod\Helpful\FunctorLaws::test
FunctorLaws