/r/scala
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
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.
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?
Get the full newsletter and check the upcoming events here: https://scalac.io/blog/scalendar-february-2025/
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.
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?
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.
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.
Does anyone know any library that allows to use the Gradio (Python library) in Scala?
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.
Several Scala meetups powered by Scalac are planned for the near future - below are the links if you're interested in the topics:
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
https://jobs.ashbyhq.com/chilipiper/ab556557-83cf-467d-90fb-5119dabf146c?utm_source=0olvY1V6eo
UPDATE:
The salary range for this role is between $87K – $138K • Offers Equity • Final compensation is determined by experience, skills, and location
#
# 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:
#
#
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.
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.
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)
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! 🙂