DZone

Over the course of my career, a problem that I have had to face fairly repeatedly is dealing with a nested tree-like structure with arbitrary depth. From XML to directory structures to building data models, nested trees or documents are a common and pretty useful way to model data.

Early in my career (classic Java/J2EE/Spring days), I tackled them using the classic Visitor pattern from the Gang of Four and have probably had more than my fair share of implementing that pattern. Then, whilst working in Groovy, I re-imagined the pattern a little to make it a little more idiomatic (dealing with mostly Maps and Lists) and, now, I am working in Scala, and once again the problem has arisen.

Source: DZone