3 ms·
How dare people have new ideas. For those that don’t hate new ideas, functors and the like allow you to write transformations on data in terms of elements, rat
by dmkolobov 2y ago
How dare people have new ideas.
For those that don’t hate new ideas, functors and the like allow you to write transformations on data in terms of elements, rather than the structure of the container. This means that it doesn’t have access to things like neighboring elements or the size of the overall structure( unless other traits which provide those capabilities are mentioned in the trait bounds ). Such well-known algebraic restrictions can be useful for managing complexity when writing compilers or other data pipelines.
The simplest use-case is when you want to use an algorithm across multiple representations of a data structure(list vs array, for example).