Pre-generics libraries for creating common FP functions
With or without generics, it is common to operate on collection-style data structures in any programming language. Storing a series of values, whether it is a list of numbers representing scores on a test or a collection of structs such as all employees working in a hospital, is common enough that you’ll run into these data structures sooner rather than later. The operations that are performed on these can also fall into a few categories, especially once we abstract them into higher-order functions. You either have to modify the data elements in some way (for example, multiplying all the values by two) or modify the container in some way (for example, removing all the odd numbers). As we have seen, rather than implementing a function such as removeOdds
or multiplyNumbers
, what we’d like to write is just a function that can filter any element based on a predicate or change an element based on a transformation (these...