Hacker News new | ask | show | jobs
by tmoertel 532 days ago
What's particularly interesting is that folds are not limited to processing lists. For any recursive data structure, you can create a corresponding fold. What's even more interesting is that you can organize your code to automatically create the corresponding fold from a given recursive data structure!

Here's one example I wrote up using trees as the data structure:

https://github.com/tmoertel/practice/blob/master/EPI/09/soln...

Here's another example, this one in Python: https://github.com/tmoertel/practice/blob/master/dailycoding...

1 comments

Yes, that is because folds work on catamorphisms in category theory.
Indeed! The first example I linked to explains this connection in detail.