From 5ee5755a78f8de2a15c35c3b3cd2860734e93e0a Mon Sep 17 00:00:00 2001 From: Theo Gotsopoulos Date: Mon, 10 Mar 2025 23:02:02 +0000 Subject: [PATCH 1/3] Minor change on do-notation to use pipe operator --- src/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 48198d5..549143a 100644 --- a/src/functions.php +++ b/src/functions.php @@ -147,7 +147,7 @@ function dn(MonadInstance $ma, callable ...$fs) { $last = $ma; foreach ($fs as $new) { - $last = $last->bind($new); + $last = $new |> $last->bind(...); // Pedantic type check below if (!$last instanceof MonadInstance) { From fcd0f2861afd44c3d54ce04f0d6ef3fe75ceddb8 Mon Sep 17 00:00:00 2001 From: Theo Gotsopoulos Date: Mon, 10 Mar 2025 23:56:25 +0000 Subject: [PATCH 2/3] Add some bad looking ones with non unary null |> $f Essentially is $f() assuming $f is callable --- src/Data/IO.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/Data/IO.php b/src/Data/IO.php index bc0c28f..0f38430 100644 --- a/src/Data/IO.php +++ b/src/Data/IO.php @@ -85,8 +85,7 @@ public function fmap(callable $f): FunctorInstance // todo: self or static? return new self( function () use ($f) { - $result = ($this->action)(); - return $f($result); + return ($this->action)() |> $f; } ); } @@ -116,11 +115,10 @@ public function sequence(ApplicativeInstance $fa): ApplicativeInstance } // todo: rewrite this in a more concise manner, but for brevity now: - $do = function () use ($fa) { - $f = $this(); - $g = $fa(); - return partial ($f) ($g); - }; + $do = fn () + => null |> $fa + |> partial (null |> $this); + return IO::inject($do); } @@ -149,10 +147,8 @@ public function bind(callable $f): MonadInstance { $action = $this->action; $do = function () use ($f, $action) { - $x = ($action)(); - // todo: could add a type check here? that return type is indeed m b ? - return (partial ($f) ($x)) + return (null |> $action |> partial ($f)) ->getValue(); // unIO }; return new IO($do); From b6f701383b46c23a7fca90af26e4be7b29d495e5 Mon Sep 17 00:00:00 2001 From: Theo Gotsopoulos Date: Tue, 11 Mar 2025 21:13:14 +0000 Subject: [PATCH 3/3] Add example with possible issue --- examples/namespaced-fn.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 examples/namespaced-fn.php diff --git a/examples/namespaced-fn.php b/examples/namespaced-fn.php new file mode 100644 index 0000000..9429115 --- /dev/null +++ b/examples/namespaced-fn.php @@ -0,0 +1,26 @@ + myFunc(...); // exception, see below + print $result . "\n"; // works + + /** +Fatal error: Uncaught Error: Call to undefined function myFunc() in /home/thgs/Projects/Functional-PHP/functional/examples/namespaced-fn.php:15 +Stack trace: +#0 {main} + thrown in /home/thgs/Projects/Functional-PHP/functional/examples/namespaced-fn.php on line 15 + + I am at d5a5dc8d (func-composition) + */ +}