Posts in the “scala” category

Setting a Scala application's command line parameters in Eclipse

I’ve been developing a new Scala application named Cato that requires some command-line parameters, and I just had to figure out how to configure Eclipse so my application would get those parameters. Doing this with Scala in Eclipse is different than configuring Java command line parameters in Eclipse, so I thought I’d share the recipe.

Fortunately it’s just a two-step process. First, click the drop-down icon next to the “Run” button and choose “Run Configurations”, as shown here:

Scala YAML parser examples using Snakeyaml

Summary: A Scala YAML parsing example using the Snakeyaml parser.

If you need some Scala YAML parsing examples using Snakeyaml parser, you've come to the right place. I just worked through some Snakeyaml issues related to Scala, in particular converting YAML to JavaBean classes written in Scala, so I thought I'd share the source code here.

Functional Programmers are Better Programmers?

I won’t link to it (because it’s a link-bait article), but I was surprised to see that medium.com ran a little article (very little), titled, “Functional Programmers are Better Programmers.” This image shows the crux of the article. I was surprised that the authors come right out and state, “Yes, FP is more difficult.”

Scala: Deeper XML parsing, and extracting XML tag attributes

Problem: You need to perform deep XML searches, combining the \ and \\ methods, and possibly searching directly for tag attributes.

Solution

Combine the \\ and \ methods as needed to search the XML. When you need to extract tag attributes, place an @ character before the attribute name.

Given this simplified version of the Yahoo Weather RSS Feed:

Scala: Extracting data from an array of XML elements

Problem: Your XML data has an array of elements, and you need to extract the first element, second element, or more generally, the Nth element, using Scala.

Solution

The following simplified version of the XML from the Yahoo Weather API has three <forecast> elements:

Passing arrays back and forth between Scala and Java

Scala FAQ: How can I pass an array back and forth between Scala and Java code?

Solution

The first link in the See Also section states, “Scala arrays correspond one-to-one to Java arrays,” and as a result of this, passing arrays back and forth between Java and Scala code is easier than the example shown in Recipe 17.1 in the Scala Cookbook, “Going to and from Java Collections.”

No new book chapters this weekend

FWIW, I don’t think I’ll be posting any new chapters for my “Functional Programming in Scala” book this weekend. I had a bad episode at the grocery store this morning (I started shaking, dropped a half-gallon of milk, it exploded and flew everywhere), so I’m back to seeing doctors again. I’ll post an update here as soon as I’m able to release any new book chapters.

Can Scala have a highly parallel typechecker?

If you’re interested in the details of how Scala works, such as its compiler, this medium.com article by Grzegorz Kossakowski is a good read. In the summary he states:

“I believe the architecture of Hack’s highly parallel and distributed typechecker can be stolen and brought to Scala. Scala’s rich type system poses some challenges that Hack’s typechecker implementators didn’t need to worry about but I don’t see inferred return types or path-depent types as showstoppers.”

A Scala "open URL as InputStream" method (HttpURLConnection)

As a quick note, I just found this getUrlInputStream method in an old Scala project. It needs to be updated and cleaned-up, but if you are looking for some code to get you started with opening a URL as an InputStream in Scala, this may be helpful: