/r/scala

Photograph via snooOG

Information Regarding Scala:

Platforms

Community

Coding Tools:

IDES / Programming Environments

Build Tools

Code Formatting / Linting

Free Books, Tutorials and Guides:

Non-free Books:

Advanced!:

Free Scala Courses:

Scala Conferences:

Podcasts:

Scala Jobs:

Scala Libraries:

Web Development and Microservices

Web Front End (Scala.js)

Database Access

Functional Programming

Concurrency / Parallelism

Mathematics

Distributed Computing

Blockchain

Monitoring/instrumentation:

Miscellaneous:

Open Source Applications written in Scala

Want your library here? Message the moderators!

Related Communities:

Blogs/Periodicals:

/r/scala

54,155 Subscribers

3

Cask template for a ReST JSON API

Hey,

I am slowly building a set of templates to make it easy for people to start projects quickly, but also release updates across all their generated code simply.

Today, I am sharing my latest template for the cask framework.

https://github.com/template-driven-development/templates/blob/main/scala/213/cask/rest-json-api.scala

TL;DR; The template maps ReST calls to strongly typed Scala functions. In that process, it handles JSON conversions, status code, and the likes, leaving you to only implement the CRUD logic.

Would you have any suggestions to improve this template?

0 Comments
2025/02/03
22:54 UTC

8

[Events] Scala, Frontend and Software Architecture | Scalendar February 2025

Get the full newsletter and check the upcoming events here: https://scalac.io/blog/scalendar-february-2025/

0 Comments
2025/02/03
11:20 UTC

14

Is ZIO knowledge transferable to cats and cats-effect?

I'm on an endless onboarding process in Scala. It's taking a lot of time because I often need to switch between projects done with other languages. To solve this issue, I decided to do a personal project in Scala, I think this will be the only way to have the immersion needed to understand the language and ecosystem. I've raised a post like this a while ago, but it was more related to Scala and not the effect system libraries, so bear with me. I coded for most of my career with mainstream languages but I have a very limited experience with functional langues like Erlang.

I would like to follow the path of least resistance. I understand how powerful these effect systems are, but I would rather be with something that has 80% of the features while being just 20% of the complexity. From what I've read on the internet, looks like ZIO is the answer, it's opinionated, but simpler, and I'm all about tradeoffs. But the issue is, it doesn't matter if I learn ZIO because on the company that I work, most of the projects are very legacy and based on things like Scalaz, newer ones are on Akka, and there are a handful of services using cats-effect with Http4s.

So my point is, I would like to give a fair try on using Scala outside of work, although I'm still very reluctant because on my day to day job, the Scala services proven to be as reliable as everything else, while having way worse maintenance costs. But maybe this is just an issue on my job and not on the language, that's why I want to discover on my own. But like everyone else, time is limited, and I don't want to invest a lot of time on something, ZIO, if it does not translate to the things I need to learn at my job, cats/cats-effect (there is some desire on moving to cats-effects for all the new services).

Right now I'm reading the first version of the red book and doing the exercises.

14 Comments
2025/02/03
10:07 UTC

17

Scala Junior/Mid -> Start to learn Scala Cats or ZIO?

Hey,

I am junior/mid Big Data Engineer, what is better library to learn right now - scala cats or scala zio? Google trends shows that scala cats may be better option here. What is yours opinion?

https://preview.redd.it/ula34dnyzqge1.png?width=1184&format=png&auto=webp&s=5d5327d4e413904cbb14dd94a8af69d954653aff

21 Comments
2025/02/02
15:56 UTC

29

Are we ever going to get actual Scala 3 support on Android?

I'm trying to write a fancy multilingual Soft Keyboard/IME for English and (historical and modern) southeast asian languages meant partially for linguistics work, but it's really frustrating to try to make with Kotlin. I'm not much of a good programmer in the first place, but Scala makes everything easy for me because of the flexibility in data structures and how easy it is to make really complex things usable in a simple and concise/terse manner. And I really utilize the pattern matching for this specific type of thing. I feel like I'm not afforded anywhere near as much of that with Kotlin, although it probably doesn't help that I don't actually normally use nor know much Kotlin...

I'm easily able to write a similar application with Scala for the JVM, but when it comes to Android it seems Scala support is either not worth the trouble or (for Scala 3) almost non-existent. And it's been that way for so long that I fear it'll never happen... I would think that, Android and Google being as big as they are, they would put at least some resources into JVM languages other than Java/Kotlin, but it seems not.

6 Comments
2025/02/02
02:52 UTC

9

Best LLMs for generating valid Scala code

Hey everyone, which open source open weights LLMs in your experience generate valid Scala code? By valid I mean compiling with proper libs and their versions.

14 Comments
2025/01/31
16:37 UTC

34

Functional PostgreSQL without JDBC - Jesper Öman, Scala Stockholm Winter Meetup, Nov 2024 Part 1

3 Comments
2025/01/31
12:55 UTC

3

Using Python Gradio in Scala

Does anyone know any library that allows to use the Gradio (Python library) in Scala?

1 Comment
2025/01/30
16:47 UTC

39

What's the simplest way to deploy a Scala web service?

Hi, for the last many years I've been working as a Scala engineer in large companies on business critical applications with millions of users running in multiple regions with auto scaling and fully automated deployments with no downtime. Just like many people here, I'm sure.

I'm now working on a small personal application that needs none of that. I've just got a $10 per month VPS and a GitHub account, and I have no idea how to even deploy the application.

Does anyone have any experience or advice on how to setup and deploy a simple non-critical Scala application? What's the minimum needed to get it to serve traffic over the internet?

Do I need an nginx server, or can I just run the artifacts from ABT assembly or native packinger?

Can deploy via ftp or ssh or scp? And can I do it with GitHub Actions?

Any help would be appreciated. Thanks.

20 Comments
2025/01/30
13:45 UTC

19

[Scala meetups] Functional World | ScaLatin

Several Scala meetups powered by Scalac are planned for the near future - below are the links if you're interested in the topics:

  • February 19Functional World #15 | Repurposing Scala's Pattern Matching for Deeply Embedded
  • March 11Functional World #16 | Scala in 2025: How to Start, What to Learn – something for beginners in the Scala world and those looking for a fresh perspective!
  • March 18ScaLatin #9 | El pegamento galáctico - meetup conducted in Spanish
0 Comments
2025/01/29
12:02 UTC

42

Google Summer of Code 2025: Call for Scala projects

deadline is February 7

Are you an open source Scala maintainer? The Scala Center is preparing to participate in Google Summer of Code 2025 (GSoC), and we’re on the lookout for projects to include in this year’s program

read on: https://www.scala-lang.org/blog/2025/01/28/gsoc-projects.html

2 Comments
2025/01/28
21:30 UTC

40

Hiring a new engineer with Scala and LLMs experience

https://jobs.ashbyhq.com/chilipiper/ab556557-83cf-467d-90fb-5119dabf146c?utm_source=0olvY1V6eo

  • Completely remote
  • Needed experience with LLMs
  • Our stack is Scala, Cats Effect, microservices, GCP, Postgres, Kafka
  • Experience with LLMs is more important that Scala experience, if willing to learn
  • I'll be happy to answer any questions

UPDATE:

The salary range for this role is between $87K – $138K • Offers Equity • Final compensation is determined by experience, skills, and location

26 Comments
2025/01/28
11:44 UTC

13

Any idea what's causing this? My program has crashed 3 times in the last week randomly after migrating to scala 3.6.3 and Corretto-23.0.1.8.1.

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000001a307c566a3, pid=18796, tid=37200
#
# JRE version: OpenJDK Runtime Environment Corretto-23.0.1.8.1 (23.0.1+8) (build 23.0.1+8-FR)
# Java VM: OpenJDK 64-Bit Server VM Corretto-23.0.1.8.1 (23.0.1+8-FR, mixed mode, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, windows-amd64)
# Problematic frame:
# J 1902 c2 scala.collection.ArrayOps$.filterNot$extension(Ljava/lang/Object;Lscala/Function1;)Ljava/lang/Object; (415 bytes) @ 0x000001a307c566a3 [0x000001a307c56200+0x00000000000004a3]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#
#
13 Comments
2025/01/27
19:15 UTC

17

yantl: a newtype library that cares about error localization

0 Comments
2025/01/26
21:26 UTC

28

Announcing ZIO Apache Arrow library

Yet another library to empower the ZIO ecosystem. This time, I want to share a unique library to make your life easier when dealing with the Apache Arrow format - ZIO Apache Arrow.
At the moment, in addition to basic functionality, it provides a module for working with Datafusion.
The core module allows you to integrate with other fabulous projects from the Arrow ecosystem, such as Polars, Apache Iceberg, and more.

1 Comment
2025/01/26
18:23 UTC

98

I lost my appetite for Java after learning Scala, Is this a good or bad thing?

104 Comments
2025/01/26
09:31 UTC

2

Play Framework ReST API router / controller - feedback

Hi everyone,

I’m looking for feedback on something I’m working on. My goal is to create something generic and easily reusable, but I want to ensure I haven’t overlooked anything important.

If anyone has a few minutes to share constructive criticism, I’d really appreciate it.

Thanks

--- edit 1

After receiving feedback, I am breaking the file into smaller more digestible snippets.

The router

Instead of writing each route in the conf/routes file, I use sird to only require 1 line in the routes file

class PostRouter u/Inject() (controller: PostController) extends SimpleRouter {
  override def routes: Routes = {
    case GET(p"/")       => controller.index
    case POST(p"/")      => controller.create
    case GET(p"/$id")    => controller.show(id)
    case PATCH(p"/$id")  => controller.update(id)
    case PUT(p"/$id")    => controller.update(id)
    case DELETE(p"/$id") => controller.destroy(id)
  }
}

The controller

The controller is mostly boilerplate to read the HTTP request into Scala, and write the Scala response into JSON. Each function can be broken down into parsing the request, calling an injected handler, recovering (just in case), and returning the appropriate response.

u/Singleton
class PostController u/Inject() (handler: PostHandler, cc: ControllerComponents)(
    implicit ec: ExecutionContext
) extends AbstractController(cc) {

  def index = Action.async {
    handler.index
      .recover(PostHandlerIndexResult.Failure(_))
      .map {
        case PostHandlerIndexResult.Success(value) => Ok(Json.toJson(value))
        case PostHandlerIndexResult.Failure(e) =>
          InternalServerError(e.getMessage)
      }
  }

  def create = Action.async { req =>
    val form = req.body.asJson.flatMap(_.asOpt[PostForm])

    form
      .fold(
        Future.successful(
          PostHandlerCreateResult.InvalidForm: PostHandlerCreateResult
        )
      ) { form =>
        handler
          .create(form)
      }
      .recover { PostHandlerCreateResult.Failure(_) }
      .map {
        case PostHandlerCreateResult.Success(value) =>
          Created(Json.toJson(value))
        case PostHandlerCreateResult.InvalidForm => BadRequest("Invalid form")
        case PostHandlerCreateResult.Failure(e) =>
          InternalServerError(e.getMessage)
      }

  }

  def show(id: String) = Action.async {
    handler
      .show(id)
      .recover { PostHandlerShowResult.Failure(_) }
      .map {
        case PostHandlerShowResult.Success(value) => Ok(Json.toJson(value))
        case PostHandlerShowResult.NotFound       => NotFound
        case PostHandlerShowResult.Failure(e) =>
          InternalServerError(e.getMessage)
      }
  }

  def update(id: String) = Action.async { req =>
    val form = req.body.asJson.flatMap(_.asOpt[PostForm])

    form
      .fold(
        Future.successful(
          PostHandlerUpdateResult.InvalidForm: PostHandlerUpdateResult
        )
      ) { form =>
        handler
          .update(id, form)
      }
      .recover { PostHandlerUpdateResult.Failure(_) }
      .map {
        case PostHandlerUpdateResult.Success(value) => Ok(Json.toJson(value))
        case PostHandlerUpdateResult.InvalidForm => BadRequest("Invalid form")
        case PostHandlerUpdateResult.NotFound    => NotFound("")
        case PostHandlerUpdateResult.Failure(e) =>
          InternalServerError(e.getMessage)
      }

  }

  def destroy(id: String) = Action.async {
    handler
      .destroy(id)
      .recover { PostHandlerDestroyResult.Failure(_) }
      .map {
        case PostHandlerDestroyResult.Success  => NoContent
        case PostHandlerDestroyResult.NotFound => NotFound
        case PostHandlerDestroyResult.Failure(e) =>
          InternalServerError(e.getMessage)
      }
  }
}

The handler

The handler can be seen as a typed controller.

trait PostHandler {
  def index: Future[PostHandlerIndexResult]
  def create(form: PostForm): Future[PostHandlerCreateResult]
  def show(id: String): Future[PostHandlerShowResult]
  def update(id: String, form: PostForm): Future[PostHandlerUpdateResult]
  def destroy(id: String): Future[PostHandlerDestroyResult]
}

To handle errors, e.g. updating a record that doesn't exist, the return types are "enums". While quite verbose, it makes the handler framework agnostic.

sealed abstract class PostHandlerIndexResult extends Product with Serializable
object PostHandlerIndexResult {
  final case class Success(value: List[Post]) extends PostHandlerIndexResult
  final case class Failure(cause: Throwable) extends PostHandlerIndexResult
}

sealed abstract class PostHandlerCreateResult extends Product with Serializable
object PostHandlerCreateResult {
  final case class Success(value: Post) extends PostHandlerCreateResult
  final case object InvalidForm extends PostHandlerCreateResult
  final case class Failure(cause: Throwable) extends PostHandlerCreateResult
}

sealed abstract class PostHandlerShowResult extends Product with Serializable
object PostHandlerShowResult {
  final case class Success(value: Post) extends PostHandlerShowResult
  final case object NotFound extends PostHandlerShowResult
  final case class Failure(cause: Throwable) extends PostHandlerShowResult
}

sealed abstract class PostHandlerUpdateResult extends Product with Serializable
object PostHandlerUpdateResult {
  final case class Success(value: Post) extends PostHandlerUpdateResult
  final case object InvalidForm extends PostHandlerUpdateResult
  final case object NotFound extends PostHandlerUpdateResult
  final case class Failure(cause: Throwable) extends PostHandlerUpdateResult
}

sealed abstract class PostHandlerDestroyResult extends Product with Serializable
object PostHandlerDestroyResult {
  final case object Success extends PostHandlerDestroyResult
  final case object NotFound extends PostHandlerDestroyResult
  final case class Failure(cause: Throwable) extends PostHandlerDestroyResult
}

While this looks like a lot of code, the underlying idea is to generate it like Rails, Laravel, and others. The template isn't meant as a silver bullet. It can be seen as an easy way to prove ideas or a different way to write code, i.e. maintain a template and generate N controllers.

8 Comments
2025/01/25
22:41 UTC

0 Comments
2025/01/25
14:20 UTC

28

ZIO is not ready for the production. No way. And I guess no hope.

  1. Badly documented. Terrible. From the very beginning. Even as simple as ZConfig and ZLogging can not be just used without days(!!!) of trying and crying. Every(every!) sample uses different approaches and there's no one end-to-end working snippet.
  2. No best practices. It seems every contributor adds its own API and nobody knows that all provide*, *fromZIO, *Partial, *Some, *WithZIO are for, anyway most of times none of them even compile
  3. The codebase is cryptic so no hope to get understanding from reading sources
  4. It could be forgivable if it worked flawlessly after it has beed compiled, as FP assumes. But it does not. Forked http server does not accept connections. Without a word of debug or warning messages. Yes, it works if it forked in the main function, so the all the simple (primitive) examples are ok, but just try to move it to the helper function and start to tear your hear. No onExit, onDone, onInterrupted handlers triggerd, the only vague debug messages the "InterruptedException was ignored" and that's all. I assume there's something with Scope management that made the server exit the loop but did not complete the effect but i guess there no a one in the whole University including the author who understands all the magic behind Scopes and environments.

The root of the problem as I see it ZIO depends heavily on the stateful internals. All that Refs you know. And the overall complexity combined with lack of the resources caused that internal stateful behaviour buggy and unpredictable. The attempt to leave tagless final behind has failed.

Guys, I beg you, let's start write real world production code, let's stop give a birth half-working frameworks depending on another half-working framework, 500+ pages books and 1.5 hours videos (anyway among dozen attempts to explain tagless final there's no one successful and there's only one book worth to read "Effects with cats" or something)

134 Comments
2025/01/25
01:06 UTC

34

FastScala web framework update: new components & website

Hey everyone,

Just wanted to share some updates on the FastScala web framework: I've remodeled the website and added a good number of extra components/functionalitites lately, in can you're curious to take a look: https://www.fastscala.com/

Looking forward to your feedback! 🙂

3 Comments
2025/01/24
23:54 UTC

28

Mill: A JVM Build Tool based on Pure Functional Programming, Functional Conf 24 Jan 2025

1 Comment
2025/01/24
22:16 UTC

18

I've just begun picking up Scala, as I already know Java and would like to work as a Data Engineering team. I feel that while it is improving me as a programmer, and I enjoy it, I also have a dire need to be a little career oriented and pragmatic. Is it necessary or is Python sufficient?

18 Comments
2025/01/24
17:38 UTC

Back To Top