Posts in the “scala” category

Free books and online video courses from Alvin Alexander

As a quick note today, here’s a list of my currently-free books and online video courses about the Scala programming language and functional programming (as of October, 2024):

These books and courses are free thanks to the generosity of Ziverge. If you ever want to pay them back, check out their “on-demand team extension services.”

A ZIO 2 logging example, with a custom log format

If you’re interested in logging in a ZIO application, the following example shows a collection of different ways you can write log messages. I also show how to create your own custom log format, so the output logging from this application looks like this:

ZIO HTTP: A collection of Route examples

I try not to do this too often, but here’s a currently-incomplete list of ways to define ZIO HTTP routes. I start with some of the simplest examples, and then make them more complicated as I go along:

ZIO: A ZIO 2 + Scala 3 + MySQL database + ZIO HTTP server example application

Without much explanation, the purpose of the following ZIO 2 + Scala 3 code is to show the absolute basics of a working ZIO HTTP + MySQL application. In this case I use the Scalikejdbc library, but as you can see from the code, you can use any Scala, Java, or JVM SQL library you want.

This is almost the “simplest possible”, “Hello world” application that shows all these features.

Very soon I will have a much more complete example including the use of packages, configuration, repository, service, api, and logging, in my free video courses at LearnScala.dev.

Here’s the code:

Last draft of the Scala Cookbook

On May 24, 2013, I finished with the last hardcopy chapters of the Scala Cookbook. I put all of the chapters next to the paper shredder as a way to show what I had just done. The final edits would be finished with a copywriter over the next several weeks, and I signed off on the final edition while I was at Virginia Beach.

Benefits of GraphQL vs REST and gRPC

GraphQL FAQ: What are the benefits of GraphQL, and how does it compare to competing technologies?

This is another blog post in my series of “Conversations with robots.” In this post we look at GraphQL, and the pros and cons of how it compares to REST and gRPC.

2024 holiday season: Reduced prices on my Scala and functional programming Kindle books

I know that a lot of people devalue products when they’re free or inexpensive, and I know this sounds corny, but I always hope that somewhere out there in the world there’s a programmer/developer that works hard, but for one reason or another can’t quite grok Scala and/or functional programming, but then they find one of my books, and the light bulb goes on over their head. And then they start writing better code, and they’re happier with their work, other people are happier with their work, and they make a little more money than they might have made otherwise.

With that in mind, I’ve lowered the price of my Kindle books to just $2.99 (USD) for the 2024 holiday season. Here’s Learn Functional Programming The Fast Way, and here’s Learn Scala 3 The Fast Way.

Also, please note that the PDF versions of these books are FREE.

Enjoy, and I hope they help. :)

The Scala-CLI/Coursier cache location on a Mac/macOS system

As a brief note, my Mac/macOS system disk was pretty full, so I started looking at things I could delete easily. One thing I found is that the Scala-CLI/Coursier cache is location in this Mac directory:

/Users/al/Library/Caches/Coursier

I don’t know yet if it’s safe to delete anything in that directory/folder, but it’s using 7.2GB of space, so I’m about to look into it.

UPDATE: Here is information on deleting the scala-cli/Coursier cache.

Note that I deleted everything in that Coursier directory, and after that NONE of my Java and Scala tools worked, and I had to manually run commands like this to get Java working again:

eval "$(cs java --jvm 11 --env)"

and then later I had problems with scala-cli and had to run this command to kill bloop:

scala-cli --power bloop exit

A ZIO 2 cheatsheet

April, 2024 Update: This ZIO cheatsheet is currently being updated to ZIO 2.x, but it’s still a work in progress.

If you want a good cheat sheet right now, see this one on github. I’m creating my own as I learn ZIO and read the ZIOnomicon book. During the learning process I find that it’s much better to create your own by hand, that way you get something that’s meaningful to you.

Note that almost all of these initial examples come from the ZIOnomicon book and the video that I link to later.

The ZIO Scaladoc

Here’s a link to the ZIO Scaladoc. That’s for the companion object, and this link is for the companion trait.

A ZIO HTTP “Hello, world” example with description and key points

Here’s a brief Scala ZIO HTTP “Hello, world” example from that repository, followed by a description of the code and “key points” to know about the example:

import zio.*
import zio.http.*

object HelloWorld extends ZIOAppDefault:

    // responds with plain text
    val homeRoute =
        Method.GET / Root -> handler(Response.text("Hello, World!"))

    // responds with JSON
    val jsonRoute =
        Method.GET / "json" -> handler(Response.json("""{"greetings": "Hello World!"}"""))

    // create HTTP route
    val app = Routes(homeRoute, jsonRoute)

    // run it like any simple app
    override val run = Server.serve(app)
                             .provide(Server.default)