diff --git a/composer.json b/composer.json index 10fbbfa..470005c 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "widmogrod/php-functional", "description": "Functors, Applicative and Monads are fascinating concept. Purpose of this library is to explore them in OOP PHP world.", "require": { - "php": ">=7.1", + "php": "^7.1|^8.0", "functional-php/fantasy-land": "^1" }, "require-dev": { diff --git a/example/FreeBddStyleDSLTest.php b/example/FreeBddStyleDSLTest.php index 37e29ba..f76a92d 100644 --- a/example/FreeBddStyleDSLTest.php +++ b/example/FreeBddStyleDSLTest.php @@ -13,7 +13,7 @@ use function Widmogrod\Functional\push_; use function Widmogrod\Monad\Free\foldFree; use function Widmogrod\Monad\Free\liftF; -use function Widmogrod\Useful\match; +use function Widmogrod\Useful\matchPatterns; interface ScenarioF extends Functor { @@ -162,7 +162,7 @@ function Given(string $desc, $state): Scenario */ function interpretScenario(callable $interpretAction, callable $interpretAssertion, ScenarioF $f) { - return match([ + return matchPatterns([ Given::class => function (Given $a): State { return State::of(function () use ($a) { return [$a->next, $a->state]; diff --git a/example/FreeCalculatorTest.php b/example/FreeCalculatorTest.php index 9a78bfd..ca5c746 100644 --- a/example/FreeCalculatorTest.php +++ b/example/FreeCalculatorTest.php @@ -14,7 +14,7 @@ use function Widmogrod\Functional\bindM2; use function Widmogrod\Monad\Free\foldFree; use function Widmogrod\Monad\Free\liftF; -use function Widmogrod\Useful\match; +use function Widmogrod\Useful\matchPatterns; /** * Exp a next @@ -201,7 +201,7 @@ function square(MonadFree $a): MonadFree */ function interpretInt(ExpF $f) { - return match([ + return matchPatterns([ IntVal::class => function (int $x, callable $next): Identity { return Identity::of($x)->map($next); }, @@ -227,7 +227,7 @@ function interpretInt(ExpF $f) */ function interpretPrint(ExpF $f) { - return match([ + return matchPatterns([ IntVal::class => function (int $x, callable $next): Identity { return Identity::of(Stringg::of("$x"))->map($next); }, @@ -259,7 +259,7 @@ function interpretPrint(ExpF $f) */ function optimizeCalc(ExpF $f) { - return match([ + return matchPatterns([ IntVal::class => function ($x, callable $next) { return new IntVal($x, $next); }, diff --git a/example/FreeMonadTest.php b/example/FreeMonadTest.php index e3cd3c0..03ee04e 100644 --- a/example/FreeMonadTest.php +++ b/example/FreeMonadTest.php @@ -14,7 +14,7 @@ use const Widmogrod\Monad\IO\pure; use const Widmogrod\Monad\State\value; use function Widmogrod\Functional\fromNil; -use function Widmogrod\Useful\match; +use function Widmogrod\Useful\matchPatterns; interface TeletypeF extends Functor { @@ -106,7 +106,7 @@ function exitSuccess_() // run :: TeletypeF -> IO () function interpretIO(TeletypeF $r) { - return match([ + return matchPatterns([ PutStrLn::class => function (PutStrLn $a) { return IO\putStrLn($a->str)->map(function () use ($a) { return $a->next; @@ -126,7 +126,7 @@ function interpretIO(TeletypeF $r) // runTest :: TeletypeF -> State MonadFree [] function interpretState(TeletypeF $r) { - return match([ + return matchPatterns([ PutStrLn::class => function (PutStrLn $a) { return State::of(function (Listt $state) use ($a) { return [ diff --git a/example/FreeUnionTypeGeneratorTest.php b/example/FreeUnionTypeGeneratorTest.php index a2e5b1b..d31743b 100644 --- a/example/FreeUnionTypeGeneratorTest.php +++ b/example/FreeUnionTypeGeneratorTest.php @@ -18,7 +18,7 @@ use function Widmogrod\Functional\reduce; use function Widmogrod\Monad\Free\foldFree; use function Widmogrod\Monad\Free\liftF; -use function Widmogrod\Useful\match; +use function Widmogrod\Useful\matchPatterns; /** * type UnionF _ next @@ -263,7 +263,7 @@ public function __toString() */ function interpretTypesAndGenerate(UnionF $f): Identity { - return match([ + return matchPatterns([ Declare_::class => function (string $name, array $args, callable $next): Identity { $a = new GeneratorLazy(); $a->declaration = [ @@ -293,7 +293,7 @@ public function test_example_1() { // $interpret :: UnionF -> Identity Free a $interpret = function (UnionF $f): Identity { - return match([ + return matchPatterns([ Declare_::class => function (string $name, array $args, callable $next): Identity { return Identity::of([ 'interface' => $name, diff --git a/src/Monad/Control/Doo/interpretation.php b/src/Monad/Control/Doo/interpretation.php index 43bd779..be6981c 100644 --- a/src/Monad/Control/Doo/interpretation.php +++ b/src/Monad/Control/Doo/interpretation.php @@ -15,7 +15,7 @@ use function Widmogrod\Functional\sequenceM; use function Widmogrod\Monad\Free\foldFree; use function Widmogrod\Monad\Reader\runReader; -use function Widmogrod\Useful\match; +use function Widmogrod\Useful\matchPatterns; /** * @var callable @@ -32,7 +32,7 @@ */ function interpretation(DooF $f) { - return match([ + return matchPatterns([ Let::class => function (string $name, Monad $m, MonadFree $next): Reader { return Reader::of(function (Registry $registry) use ($name, $m, $next) { return $m->bind(function ($v) use ($name, $next, $registry) { diff --git a/src/Useful/match.php b/src/Useful/match.php index 0d3c918..f01a8cb 100644 --- a/src/Useful/match.php +++ b/src/Useful/match.php @@ -26,7 +26,7 @@ * * @return mixed */ -function match(array $patterns, $value = null) +function matchPatterns(array $patterns, $value = null) { return curryN(2, function (array $patterns, $value) { if (count($patterns) === 0) { diff --git a/test/Useful/MatchTest.php b/test/Useful/MatchTest.php index ab4bbb3..269899c 100644 --- a/test/Useful/MatchTest.php +++ b/test/Useful/MatchTest.php @@ -6,7 +6,7 @@ use Widmogrod\Useful\PatternMatcher; use Widmogrod\Useful\PatternNotMatchedError; -use function Widmogrod\Useful\match; +use function Widmogrod\Useful\matchPatterns; use const Widmogrod\Functional\identity; use const Widmogrod\Useful\any; @@ -23,7 +23,7 @@ public function test_it_should_fail_on_not_matched_patterns( $this->expectException(PatternNotMatchedError::class); $this->expectExceptionMessage($expectedMessage); - match($patterns, $value); + matchPatterns($patterns, $value); } public function provideInvalidPatterns() @@ -61,7 +61,7 @@ public function test_it_should_match_given_value( $value, $expected ) { - $result = match($patterns, $value); + $result = matchPatterns($patterns, $value); $this->assertSame( $expected, $result