When writing programs with pure functions, it appears that there are some refactorings which are more common in this paradigm. Some of these relate to the well know catalog of refactorings introduced by Martin Fowler, but others are not on that list.
In this catalog, I want to present the ones I have personally identified, plus the additional ones propose in a session I ran at SoCraTes 2016 on this topic.
My hope is that others in the functional community will improve and extend this catalog to create a useful resource. So please contribute thoughts (issues) and (improvements) pull requests!
- Rearrange Function Parameters
- Go Point Free
- Curry Function
- Recursion to Map
- Recursion to Filter
- Recursion to Reduce
- Name Value
- Extract Function
- Name Lambda
- Compose Nested Functions
- Reduce to Map and Filter
- Map and Filter to Reduce
- Extract Parameter to Type
- Tail Call Optimise Recursion
- Replace Conditional with Polymorphism
- Chain of Consequences to Maybe (or Either) Monad
Links for further reading (not yet integrated into this document)
- http://refactoring.com/catalog/
- http://victorsavkin.com/post/63551894251/functional-refactoring-in-javascript
- https://www.cs.kent.ac.uk/projects/refactor-fp/publications/Huiqing-thesis.pdf
- https://www.cs.kent.ac.uk/projects/refactor-fp/publications/AFP04.pdf
- https://www.cs.kent.ac.uk/projects/refactor-fp/publications/ChrisThesis.pdf
- http://thepugautomatic.com/2016/01/pattern-matching-complex-strings/
- https://vimeo.com/45140590
- https://vimeo.com/122645679
- https://speakerdeck.com/lilobase/des-boucles-aux-transducers-pyconfr-2015