The idea here is to duplicate Python's itertools functionality in scala