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