Scala Bridge Workshop — Vancouver 2017

Celia S. Siu
Jul 23, 2017 · 4 min read

“Learn Scala”, was one piece advice I received when I asked a data scientist for tips on what a data scientist should know.

Last week — July 20th at the Hootsuite headquarters — I attended the ScalaBridge workshop. This workshop is a satellite event to the Scala Up North conference and was build by the Scala community to provide developers an introduction to Scala and functional programming.

Working at your own pace

At the workshop, we started the morning with a welcoming address, the schedule for the day, and topics to be covered:

  • Value and method declaration
  • Recursion
  • Functions
  • Collections

With a modest class size and plenty of mentors, we worked at our own pace through the Creative Scala tutorial. This tutorial, divided into 11 chapters, ranges from introducing values as objects to methods, recursive functions, and transforming elements in lists. Learning is by doing exercises, writing Scala, and creating pretty pictures.

Creative Scala — Chapter summaries

In Chapter 1: Getting Started, we setup of the work environment by installing the JVM, Git, a text editor (such as atom), and the template project for Creative Scala.

In Chapter 2: Expressions, Values, and Types, we learn that an expression is a fragment of Scala code, the result of running an expression is a value, and types such as strings or integers only exist at compile-time in Scala.

In Chapter 3: Computing With Pictures, we use the “Doodle” Scala library to create graphics; draw circles, rectangles, and triangles; arrange different layouts; and adjust colours in the RGB or HSL systems.

import doodle.core._
import doodle.core.Image._
import doodle.syntax._
import doodle.jvm.Java2DFrame._
import doodle.backend.StandardInterpreter._

In Chapter 4: Writing Larger Programs, we learn to work in the SBT console and to save programs as files loadable from the src/main/scala/ directory. In addition, object names were defined, vars declared, scopes created, and abstractions made.

In Chapter 5: The Substitution Model of Evaluation, we step through how expressions are evaluated.

In Chapter 6: Methods, we write methods to interact with objects.

// Method
def addTwo(x: Int) = x+2
// Function literal
(x: Int) => x+2

In Chapter 7: Structural Recursion, we write reusable code for processing any natural number. For instance:

// Place "count" number of boxes beside each other
def
boxes(count: Int): Image = {
val aBox = Image.rectangle(20, 20)
// Recursion
count match {
case 0 => Image.empty
case n => aBox beside boxes(n-1)
}
}

In Chapter 8: Horticulture and Higher-order Functions, we learn about first-class values, higher-order functions, and to convert any method to a function using the _ operator.

// Passing a function literal directly:
val blackCircles: Image =
concentricShapes(10, (n: Int) => Image.circle(50 + 5*n))

// Converting a method to a function:
def redCircle(n: Int): Image =
Image.circle(50 + 5*n) lineColor Color.red

val redCircles: Image =
concentricShapes(10, redCircle _)

In Chapter: 9 Shapes, Sequences, and Stars, we learn to represent sequences of data (representing lines and curves) and to manipulate such sequences (to build our own shapes) using higher-order functions that abstract over structural recursion. We work with lists, ranges, and transform elements in the list using map.

In Chapter 10: Turtle Algebra and Algebraic Data Types, we turn to the turtle graphics system to draw paths based on the current location. We are also introduced to a method called flatMap.

Finally, in Chapter 11: Composition of Generative Art, we add an element of randomness.

Celia S. Siu

Written by

Interested in data science, machine learning, text mining, data visualization, photojournalism, everyday life, and succulents

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade