Hacker News new | ask | show | jobs
Show HN: PHPunctional, a PHP Functional Programming Library (github.com)
37 points by r-cyr 4080 days ago
8 comments

https://github.com/r-cyr/PHPunctional/blob/master/P/Examples...

Readable? Concise? Esthetical? :)

FP with PHP is like putting a saddle on a cow.

Interesting as an experiment, but I can't really imagine using it in production - I can't imagine someone preferring to have this version of Fibonacci in their codebase over whatever any sane programmer would write instead

You should definitely add a link to your examples in your README.

For anyone else looking, they are located here: https://github.com/r-cyr/PHPunctional/tree/master/P/Examples

Thank you, just added the link to the README like you suggested
You could improve the usability of this library (or FP in PHP in general), by implementing 'string lambdas' such as those found in Oliver Steele's Functional.js[0], which was a clever, if controversial, workaround for Javascript's lack of a concise anonymous function syntax at the time.

For example

    function($n) use ($partial) { return $partial($n - 1) + $partial($n - 2); 
could become

   'partial(n - 1) + partial(n - 2)'
Compiling the string lambda to a function can be memoized with the string itself as the key (as many regex implementations do with the regex text) so each is only ever compiled once.

[0] http://osteele.com/sources/javascript/functional/

Quite jolly! I hope that performance impact is negligible.

Now it would be nice to make a wrapper to convert exception-throwing calls into Either-returning calls (or it's there and I missed it?). This would help with accessing standard / third-party libraries.

I will try to profile it soon but basically, until now, it was more about "what's possible" than "how fast can I make it" kind of project. Also, that exception-handling either is a great idea, thank you.
Have you seen this project? https://github.com/widmogrod/php-functional

Tackle problem same problem as your library, also in PHP.

Another awesome functional library / extension for PHP is https://github.com/lstrojny/functional-php
Nice work! I'll have to explore a bit more.
So, when does P#P come out?
I've been considering PCP... PHP: Compiled Perl.

Eseentially, you write Perl but get PHP. Or vice-versa. Doesn't really matter because it's a joke anyway.