This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 19.8, “Examples of how to use types in your Scala classes.”
To put what you’ve learned in this chapter to use, let’s create two examples. First, you’ll create a “timer” that looks like a control structure and works like the Unix time com‐ mand. Second, you’ll create another control structure that works like the Scala 2.10 Try/ Success/Failure classes.