Generalizing behavior
Previously, you have been promised that functions, besides types, can also be parametrized with placeholders, which this chapter aims to show. Parametrizing a function with a placeholder type works similarly to parametrizing a type, as can be seen in the following example. In the example, the function last_item always returns the last item of a list. The placeholder called T symbols the type of item in the list. The List type also requires a placeholder, which is why we can pass through T as its placeholder. Since the last item in the list is also of type T, last_item returns T as well.
We can call the function with any list as its parameter, however, we need to pass a type for T in angled brackets. We would like to call last_item on a list of numbers; therefore, T needs to be set to Number.
Output:
Similarly to functions, methods can also make use of placeholder types. In fact, placeholders are defined and used in the exact same way on methods than they do on functions.