Without any introduction or discussion, here’s a little Scala script I just wrote to read in a text file that contains stocks symbols, with one symbol per line, along with some blank lines; then convert those symbols to comma-separated output (CSV format) that I print to STDOUT:
Scala, Java, Unix, MacOS tutorials (page 18)
| Scrum! | |
|
Scrum Mastery |
I just had this problem in Scala where I wanted to concatenate two corresponding multiline strings into one final multiline string, such that the elements from the first string were always at the beginning of each line, and the lines from the second string were always second. (When I say corresponding, I mean that the two strings are of equal length.)
That is, given two Scala multiline strings like these:
If you want to get a value out of a Scala Option type, there are a few ways to do it. In this article I’ll start by showing those approaches, and then discuss the approach of using the fold method on an Option (which I’ve seen discussed recently on Twitter).
1) Getting the value out of an Option, with a backup/default value
As a first look at getting values out of an Option, a common way to extract the value out of a Scala Option is with a match expression:
Sister 1: “What about that cute guy I met? Condom Man.”
Sister 2: “Yes, that’s how he likes to be known.”
Sister 3: “Condom Man? Sounds like a superhero.”
~ from the movie, Must Love Dogs
Two sisters talking in the movie, Must Love Dogs:
“So can I ask you a question?”
“No.”
“You never would have left Kevin, would you?”
“If he hadn’t ... left me? No, I don’t think so.”
“But you weren’t really happy.”
“Well, I figured that was the life I picked, so I had to make the most of it. I’m not even sure I deserve a new life now. Sometimes I think that was supposed to be my one chance and I blew it.”
“Where did we get the bad attitudes?”
“The nuns?”
“Yeah, that works. Let’s blame the nuns.”
I need your grace
To remind me
To find my own.
~ a favorite line from the song, Chasing Cars
“Remember that you are the Witness only ... even for a moment, do not think that you are the body.”
~ Sri Nisargadatta Maharaj
If you ever want to use ImageMagick to crop a bunch of images that are in one directory, I can confirm that this command crops all the JPG images in the current folder while creating new JPG files with the new name shown:
I saw this 19th century ocean painting on Flipboard. The color/translucence of the water is incredible.
As a quick note, here’s a Scala function to generate a random integer value that will be in between the input min and max values:
As a brief note today, here’s a little Scala application that reads an HTML file, parses it with JSoup, and then I select all of the elements with the CSS selector shown. After that, I use some Scala goodness to read all the text values of those elements, see if there is a "W" (win) or "L" (loss) character there, convert that to a Seq[Boolean], and then generated an ASCII Sparkline chart based on those results.
Note that the desired CSS selectors look like this in the HTML:
If you’re interested in Sri Nisargadatta Maharaj’s best books, I share my opinions in this blog post. And just to confirm that I have bought the books I’m talking about, here’s a photo of them:

UPDATE: The latest version of this code is at github.com/alvinj/TextPlottingUtils.
Creating an ASCII version of a Sparkline chart — also known as a Win/Loss chart — in Scala turned out to take just a few lines of code, as shown in this source code:
Creating an ASCII version of a Sparkline chart — or Win/Loss chart — in Scala turned out to take just a few lines of code, as shown in this photo.
As I mentioned previously, the Neotype library is a nice improvement over the verbose Scala 3 opaque type feature. This little example begins to show how much better Neotype is than opaque types, where opaque types require more boilerplate to implement less functionality:
//> using scala "3"
//> using lib "io.github.kitlangton::neotype::0.3.0"
import neotype.*
// [1] Opaque type:
opaque type Username = String
object Username:
def apply(value: String): Username = value
// [2] Neotype:
object Password extends Newtype[String]:
override inline def validate(input: String): Boolean =
input.nonEmpty && input.length > 2
@main def NeotypeTests =
val u = Username("Alvin")
println(u)
val p = Password("12")
println(p)
“...understand always that you are the timeless, spaceless witness.”
~ Sri Nisargadatta Maharaj
As I wrote in my ZIO “mental model” and best practices article, when I work with ZIO, I like to separate (a) my application from (b) the ZIO run value. Specifically I mean that I like to handle the results of the application in the run value. (If you’ve read my previous ZIO blog posts, when I say “application,” I mean our main equation or blueprint.)
There are quite a few different ways to write a ZIO run value, and in this tutorial I want to show many of the different ways I know, or at least those I can remember today. :)
This is an example of a “radar chart,” and comes from this thoughtworks.com page. It looks like a nice way to visualize a set of characteristics. For instance, you could use a chart like this to judge different qualities about a movie, such as whether it is romantic, action-packed, and so on.
| Scrum! | |
|
Scrum Mastery |