

Show HN: PHPunctional, a PHP Functional Programming Library - r-cyr
https://github.com/r-cyr/PHPunctional

======
V-2
[https://github.com/r-cyr/PHPunctional/blob/master/P/Examples...](https://github.com/r-cyr/PHPunctional/blob/master/P/Examples/Fun.php)

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

------
rjbrock
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](https://github.com/r-cyr/PHPunctional/tree/master/P/Examples)

~~~
r-cyr
Thank you, just added the link to the README like you suggested

------
mambodog
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/](http://osteele.com/sources/javascript/functional/)

------
nine_k
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.

~~~
r-cyr
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.

------
widmogrod
Have you seen this project? [https://github.com/widmogrod/php-
functional](https://github.com/widmogrod/php-functional)

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

------
mfonda
Another awesome functional library / extension for PHP is
[https://github.com/lstrojny/functional-
php](https://github.com/lstrojny/functional-php)

------
ben_pr
Nice work! I'll have to explore a bit more.

------
gmack
So, when does P#P come out?

~~~
johnmaguire2013
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.

