We, software developers, love creating data structures and traversing them. We traverse structures so as to visit elements therein. A traversal typically uses a loop.
However, doesn't writing a for
loop (or a foreach
loop) seem like a routine job, also known as a boilerplate? I would rather concentrate on the element and let the language figure out and write the looping for me. Again, what I wish to do with each element depends on the context (that is, it varies). On the other hand, writing a for
loop seems like typing the same chars again and again.
IDEs like Eclipse provide helpful completions for such routine and boring stuff. However, could we have the loop abstracted away, and instead let it happen behind the scenes? Answer: yes, use the combinators. In fact, we have already used some in earlier chapters, foreach
and map
.
Combinators and functions come together and make the magic happen. Using combinators helps cut down on repetitive...