Drawing Trees

In the last article we saw one way of implementing Binary Search Trees and Red Black Trees. This data structure can be used to implement a Set (like we saw before), but there are many other use cases if we can augment the data stored on the nodes.

A basic, immutable Set in Scala

In the last article we saw one way of implementing an object-functional, immutable Stack data structure. Now let's see how to implement a Set data structure. A Set is a container which supports the following operations efficiently: insert: adds a new item to the Set delete: removes given item from the Set member: check if a given item is in the Set As we did before with the Stack, we can define this behavior in a Trait like the following:

A basic, immutable Stack in Scala

Scala was one language that I played around with many years back (and blogged about then). Recently, I took the excellent course on reactive programming which rekindled my interest in Scala and I decided to brush up my knowledge on it as well as functional programming.