August 2017
Intermediate to advanced
440 pages
10h
English
As we saw in the previous section, sometimes we want to extract common functionality from functions, but they differ in an operation they use. In such situations, we can still extract this functionality, but we need to provide an argument with the operation that distinguishes them. This way, any common pattern can be extracted and reused. For example, we often only need elements of the list that match some predicate, such as when we only want to show elements that are active. Classically, this would be implemented like this:
var visibleTasks = emptyList<Task>()
for (task in tasks) {
if (task.active)
visibleTasks += task
}
While it is a common operation, we can extract the functionality of only filtering ...
Read now
Unlock full access