Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions example/FreeBddStyleDSLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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];
Expand Down
8 changes: 4 additions & 4 deletions example/FreeCalculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
},
Expand All @@ -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);
},
Expand Down Expand Up @@ -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);
},
Expand Down
6 changes: 3 additions & 3 deletions example/FreeMonadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
Expand All @@ -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 [
Expand Down
6 changes: 3 additions & 3 deletions example/FreeUnionTypeGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Monad/Control/Doo/interpretation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Useful/match.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/Useful/MatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down