Thanks for writing this. I'm bookmarking it so I can refer back. I like the focus on cleanliness and the useful helper toDS function.
(And it's good to see another Scala person here in Austin!)
This is the third in a series of articles intended for Scala Beginners to understand how to write clean code using Option and Try and Either. Part one introduced these typeclasses and demonstrated how to avoid the awkward “test and unsafe-get” approach by using pattern matching of “map”. Part two introduced a slightly more involved example, and showed the problems encountered by nested map transformations that flatMap was designed to fix.
We were working on an example where we started with a case class Contact:
case class Contact(id: Int, name: String, phone: Option[String],
email: Option[String], friendIds: List[Int])
And we had…
This is a continuation of my earlier post Scala for Beginners: How to really use Option. This topic is based on a recent presentation I gave to my local Austin Scala Enthusiasts Meetup. The video and slides for that can by found on my website.
When I was writing the first article, I was trying to create a very simple example with some hypothetical
getEmail function to fetch an email address from a customer database and a
sendEmail function that would send an email invitation to someone. …
This is the first of a three-part series of articles, each of which gets you just a little further along in the journey down a really cool rabbit-hole. It is designed for any typical programmer who is picking up Scala as a new language and hasn’t been studying the finer points of Functional Programming. (But wants to learn.) Links to the other articles can be found at the end.
I’ve been programming with Scala for just a little under five years now, and I can still remember what it was like in the beginning. My “gateway drug” was Spark, and…
I’ve lately been getting myself into trouble with Arrays, and this week I’ve come to realize I just have to go cold turkey and stop using them. Well, at least 99% of the time.
Up until now, I’ve had a basic mind-set: if I want a data structure that I’m mostly traversing front-to-end, I’ll use a List. And really, I’ll more often put a Seq in my function signature because I know it’s good to program to generalized interfaces rather than concrete implementations. (A lesson I learned early in my Java days.)
But if I wanted “random access” (i.e. accessing…
Over the years of writing Scala code, my relationship with tuples and case classes has evolved. As a beginner, and coming from a Java background, I had found both to be a little weird, but now after 4–5 years and tens of thousands of lines of code, I’ve started to understand and appreciate their usefulness. In fact, I’ve found that in unexpected ways they can lead to much cleaner and flexible code.
Let’s start with a quick review.
A tuple is used when you want to represent something in a simple multi-part data structure. …
Life-long learner, foodie and wine enthusiast, living in Austin, Texas.