Functional PHP by Gilles Crettenand

Functional PHP by Gilles Crettenand

Author:Gilles Crettenand [Crettenand, Gilles]
Language: eng
Format: epub, pdf
Tags: Computers, Programming Languages, Php, General, Web
ISBN: 9781785886911
Google: 21MoDwAAQBAJ
Amazon: B01MEEHEVK
Goodreads: 34383609
Publisher: Packt Publishing
Published: 2017-02-14T05:00:00+00:00


Writer monad

If you remember, pure functions cannot have any side effects, meaning you cannot put a debug statement in them, for example. If you are like me, the var_dump method is your debugging tool of choice, so you are left with breaking your purity rule or using some other debugging techniques. Since all outputs of a function must go through its return value, one of the first ideas that comes to mind is to return a tuple of values-the original return value and any kind of debug statement you need.

This solution is, however, pretty complex to put in place. Imagine you have a function that halves a numerical value which returns the halved value and the received input for debugging purposes. Now, if you want to compose this function by itself to create a new function that returns the value divided by four, you also need to modify the inputs so that they can accept your new return format. And this goes on and on until you've modified all your functions accordingly. This also poses some issues with currying, as you now have an extraneous parameter which is not really useful if you don't care about the debug statements.

The solution you are looking for is the Writer monad. Sadly, there are no implementations in php-functional library at the time of writing.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.