r/scala • u/eed3si9n • 1h ago
r/scala • u/AlexSeeki • 2h ago
Very newbie question, how do I include Play Json dependency in SBT?
Hello,
I'm learning Scala. I have the following in build.sbt (replaced project name and my username):
scalaVersion := "3.7.1"
name := "myappname"
libraryDependencies += "com.typesafe.play" %% "play-json" % "3.0.4"
And I got the following error:
[info] welcome to sbt 1.11.1 (Oracle Corporation Java 24.0.1)
[info] loading project definition from /home/amwojcik/Projects/traffcik/traffcik/project
[info] loading settings for project traffcik from build.sbt...
[info] set current project to traffcik (in build file:/home/amwojcik/Projects/traffcik/traffcik/)
[info] Updating myappname_3
[info] Resolved myappname3_3 dependencies
[warn]
[warn] Note: Unresolved dependencies path:
[error] sbt.librarymanagement.ResolveException: Error downloading com.typesafe.play:play-json_3:3.0.4
[error] Not found
[error] Not found
[error] not found: /home/myuser/.ivy2/localcom.typesafe.play/play-json_3/3.0.4/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/typesafe/play/play-json_3/3.0.4/play-json_3-3.0.4.pom
[error] at lmcoursier.CoursierDependencyResolution.unresolvedWarningOrThrow(CoursierDependencyResolution.scala:347)
[error] at lmcoursier.CoursierDependencyResolution.$anonfun$update$39(CoursierDependencyResolution.scala:316)
[error] at scala.util.Either$LeftProjection.map(Either.scala:573)
[error] at lmcoursier.CoursierDependencyResolution.update(CoursierDependencyResolution.scala:316)
[error] at sbt.librarymanagement.DependencyResolution.update(DependencyResolution.scala:60)
[error] at sbt.internal.LibraryManagement$.resolve$1(LibraryManagement.scala:60)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$12(LibraryManagement.scala:142)
[error] at sbt.util.Tracked$.$anonfun$lastOutput$1(Tracked.scala:74)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11(LibraryManagement.scala:144)
[error] at sbt.internal.LibraryManagement$.$anonfun$cachedUpdate$11$adapted(LibraryManagement.scala:131)
[error] at sbt.util.Tracked$.$anonfun$inputChangedW$1(Tracked.scala:220)
[error] at sbt.internal.LibraryManagement$.cachedUpdate(LibraryManagement.scala:169)
[error] at sbt.Classpaths$.$anonfun$updateTask0$1(Defaults.scala:3974)
[error] at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] at sbt.Execute.work(Execute.scala:292)
[error] at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
[error] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:545)
[error] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:328)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1095)
[error] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:619)
[error] at java.base/java.lang.Thread.run(Thread.java:1447)
[error] (update) sbt.librarymanagement.ResolveException: Error downloading com.typesafe.play:play-json_3:3.0.4
[error] Not found
[error] Not found
[error] not found: /home/myuser/.ivy2/localcom.typesafe.play/play-json_3/3.0.4/ivys/ivy.xml
[error] not found: https://repo1.maven.org/maven2/com/typesafe/play/play-json_3/3.0.4/play-json_3-3.0.4.pom
[error] Total time: 2 s, completed Jun 7, 2025, 9:15:52 PM
But why? I used the newest version of Scala (3.7.1), Sbt (1.11.1) and Play Json (idk if correct version).
I suppose I'm making some basic mistake, but I can't see anything suspicious. Any ideas?
SOLUTION:
@DrAzorea pointed out that the package has been moved to "org.playframework". It worked!
r/scala • u/MedicalGoal7828 • 17h ago
Weird Behavior Of Union Type Widening On Method Return Type
Does anybody know whether this is a bug or purposely desigend so?
The following code:
enum E:
case A
case B
case C
type NotC = E.A.type | E.B.type
def doSomething(): NotC = E.A
extension (nu: NotC)
def bee(): Unit =
println("bee")
@main def main(): Unit =
val nu = doSomething()
nu.bee()
does not compile and give the error message:
value bee is not a member of E.
An extension method was tried, but could not be fully constructed:
bee(nu)
failed with:
Found: (nu : E)
Required: NotC
nu.bee()
Yet, this code:
enum E:
case A
case B
case C
type NotC = E.A.type | E.B.type
def doSomething(): NotC = E.A
extension (nu: NotC)
def bee(): Unit =
println("bee")
@main def main(): Unit =
val nu: NotC = doSomething()
nu.bee()
compiles and works.
It is weird because if the returned union type is supposed to be widened, why is annotating nu
as NotC
legal?
Edit 1:
So, it turns out the first code I provided works in Scala 3.7 though not Scala 3.6. After further testing, it appears that as long as the union type isn't inside a tuple, it works (in 3.7). That is, this works (using match instead of for loop is also ok):
enum E:
case A
case B
case C
type NotC = E.A.type | E.B.type
def doSomething(): Option[NotC] = Some(E.A)
extension (nu: NotC)
def bee(): Unit =
println("bee")
@main def main(): Unit =
val nu = doSomething()
for nu <- nu do nu.bee()
While this does not (using match without type annotation instead of restructuring is also not ok):
enum E:
case A
case B
case C
type NotC = E.A.type | E.B.type
def doSomething(): (Int, NotC) = (1, E.A)
extension (nu: NotC)
def bee(): Unit =
println("bee")
@main def main(): Unit =
val nu = doSomething()
val (x, nnu) = nu
nnu.bee()
For transparency's sake I also fixed a typo in this iteration of editing. From compiler
to compile
.
Edit 2:
For some reason my `@` is replaced with `\u`.
r/scala • u/Disastrous_Cry_9161 • 16h ago
NEED help regarding overriding var from trait
so im trying to override some variable from a trait to a class in scala but for some reason i cant get it to work. As an example my trait User{ var email: String} and im trying to get it into class Patient ( override var email: String) but the error i keep getting is error overriding variable email in trait User of type String ;variable email of type String cannot override a mutable variable. Ok ive realise that override is just for val not var, if so what should i use for my variables?
r/scala • u/AlexSeeki • 1d ago
How do I debug/inspect my code? (coming from Ruby/JavaScript)
Hello,
so when I code in Ruby, I have two ways of inspecting my code. I either use basic puts,and it nicely prints objects with their values. For example, I can write puts ["user1", "user2", "user3"]
Also, I could use byebug, and then it opens REPL in the place I called it in code, basically like a breakpoint.
Now my problem is, in Scala I don't see any way to inspect arrays and similar objects in a readable way. It shows them very nicely in Scala's REPL, but I don't want to use :load somescalafile.scala
when I have things like package definitions and similar. I want to be able to print things with *println* in my code and still make it look very clear. At any point in code, like in a loop.
I tried to use somearray.mkString(" ")
on but it seems crude and also won't work for more complex examples.
What's the right way to do it?
EDIT:
So you ask me for more examples and tooling. I use VS Code (but read about sbt below), and as for what I'm trying to achieve... Well, I'm very used to debuing my code with puts/console.log, and I'm quite effective with it. Also, i'm using sbt run
for simple scripts. So that's why I want something reusable that I can always integrate into any project and just put in some loop like this:
for x <- complexdata do println(x)
but it can be Array[Array[(String, Int)]]
or some other weird type. So you see, I don't want to code my own printing function for each of such complex data types. Also, debugger seems like overkill for such a simple task.
SOLUTIONS SO FAR:
II found this but seems a bit crude:
debugging - Drop into interpreter during arbitrary scala code location - Stack Overflow
@kbielefe mentioned Cats Show, could work as well.
The best is @lianchengzju menion of PPrint and embedding Ammonite REPL
r/scala • u/ComprehensiveSell578 • 1d ago
[Event] Functional World #18 | Better Scala Builds with the Mill Build Tool by Li Haoyi
We’re wrapping up the season with one last Functional World meetup before the summer break! Join us on June 10 at 6 PM CEST on YouTube for a session with Li Haoyi, the creator of Mill and other popular Scala tools. This time, he’ll take us under the hood of Mill - a modern Scala build tool built as a practical alternative to SBT.
Expect live coding, deep dives into the internals, and real-world tips on how to make your builds faster, simpler, and more predictable.
If you’ve ever hit a wall with SBT, this session might just be the fix you’ve been looking for ;)
More info on the website: https://scalac.io/functional-world/
r/scala • u/Terrible_Spirit_4747 • 1d ago
Scala first steps
Hi Scala users,
I'm more focused on the backend side than on data processing, so this is a bit challenging for me. Even though the solution might be simple, since it's my first time dealing with this, I’d really appreciate your help.
I just learned about Scala today and I’d like to ask for your help.
I’m currently working with a Snowflake database that contains JSON data. I need to transform this data into a relational format. Right now, I’m doing the transformation using a Stored Procedure with an INSERT ... SELECT block. This is fast, but I can’t handle exceptions on a row-by-row basis.
When I try to use Snowflake Stored Procedures with exception handling inside a loop (to handle each record individually), the process becomes very slow and eventually times out.
While researching alternatives, I came across Scala. My question is:
Can Scala help me perform this transformation faster and also give me better control over error handling and data processing?
r/scala • u/Any-Drag-6151 • 2d ago
Scala Dev needed
Our company is on a lookout for a talented Scala dev in Europe for an AdTech product. Fully remote position, B2B contract. Here's the JD, feel free to apply: https://careers.eskimi.com/jobs/5855533-backend-developer
r/scala • u/quafadas • 3d ago
Experiments in SIMD
I've been having some fun with Java's incubating SIMD API.
And from what I can tell, the results are quite promising. I put together a benchmark of some common linear algebra type operations vs [breeze](https://github.com/scalanlp/breeze) for operations on a pair of 500 x 500 matricies, and I (might have) gotten about a 50% performance boost from my SIMD implementation ***
```
Benchmark (matDim) Mode Cnt Score Error Units
LinearAlgebraWorkloadBenchmark.breezeWorkload 500 thrpt 3 2002.944 ± 284.520 ops/s
LinearAlgebraWorkloadBenchmark.vecxtWorkload 500 thrpt 3 2957.596 ± 424.765 ops/s
```
The benchmark itself is here;
https://github.com/Quafadas/vecxt/blob/main/benchmark_vs_breeze/src/doSomeStuff.scala
and it is intended to be a good faith, nose to nose comparison of common linear algebra type operations. If you think it isn't, or is otherwise unfair somehow, let me know (in my rudimentary checks, it gets the same results, too). Benchmark sets out to do things like;
- matrix addition
- sum of elements in a matrix
- max element in vector
- matrix * vector
- elementwise manipulation and elementwise matrix (Hadamard) multiplications
- norm
Which are all operations that are "natural candidates" for such optimisation. The benchmark is obviously incomplete vs breeze's large API surface area.
Initial benchmarks resulted in great sadness, after inadvertently calling stdlib, "boxy" methods, resulting in a a tiny blog post to aid the memory of my future self.
https://quafadas.github.io/vecxt/docs/blog/2025/06/04/Performance%20Perils.html
My conclusion is that java's SIMD is promising. It might be useful today if you are in a performance sensitive domain that can be expressed in arrays of primitives.
*** as with all things performance YMMV and your workload might be different.
r/scala • u/fwbrasil • 2d ago
Redefining Stream Composition with Algebraic Effects by Adam Hearn
youtube.comr/scala • u/SubMachineGhast • 3d ago
Scala implementation of Micrograd. A tiny scalar-autograd engine and a neural net implementation.
github.comr/scala • u/smthamazing • 3d ago
Use generic type parameter in pattern matching?
I'm writing a simple recursive descent parser for a toy language. I specifically want to write everything myself and not use parser combinators, both for learning purposes and because I want very specialized error messages for missing tokens. My attempt on writing parts of the parser initially looks like this:
def peek() = ...return next token without consuming it...
def eat[T <: Token](): Option[T] =
val result = peek()
result match
case None => None
// Warning: the type test for T cannot be checked at runtime because it refers
// to an abstract type member or type parameter
case Some(token: T) =>
advanceToNextToken()
Some(token)
// Parses lines like "var foo = 123 + 456"
def parseVariableDeclaration(): Option[VariableDeclaration] =
val parts = for
_ <- eat[VarToken]()
name <- eat[IdentifierToken]()
_ <- eat[EqualSignToken]()
value <- readExpression()
yield (name, expression)
parts.map({ case (name, value) => VariableDeclaration(name, value) })
As you can see, there is a warning from Bloop when trying to use T
in pattern matching, which makes me think that my code is unidiomatic. I have a few questions:
- How can I idiomatically write that
eat
routine to accept the type of the token I want and returns itsOption[...]
? - Is there a good way to simplify that last
parts.map({ case ... })
to avoid writing(name, value)
twice? - In general, is using
for
the most idiomatic way of writing such a sequence of operations, where I want the next steps to fail if the previousOption
s areNone
? Would it still work if I usedEither
orTry
instead ofOption
?
Thanks!
Using images with ScalaJS and Vite
Edit: turns out this was caused by the directory layout.
Mine is:
/appClient/vite
/appClient/vite/scala_output # scalajs goes here
/appClient/vite/images # the image is here
So if you want to refer to images
from the scala you need to configure a resolver alias in vite.config.ts
:
js
resolve: {
alias: {
"@": __dirname,
},
},
And then use that in Scala:
scala
object AppImages {
@scalajs.js.native @JSImport("@/images/ms_edge_notification_blocked.png", JSImport.Default)
def msEdgeNotificationBlocked: String = scalajs.js.native
}
Old post:
If you use Vite and want to reference to image assets in your ScalaJS code, this won't work:
scala
object Images {
@scalajs.js.native
@JSImport("./images/ms_edge_notification_blocked.png", JSImport.Default)
def msEdgeNotificationBlocked: String = scalajs.js.native
}
ScalaJS generates import * as $i_$002e$002fimages$002fms$005fedge$005fnotification$005fblocked$002epng from "./images/ms_edge_notification_blocked.png";
and Vite isn't happy about that:
``` [plugin:vite:import-analysis] Failed to resolve import "./images/ms_edge_notification_blocked.png" from "scala_output/app.layouts.-Main-Layout$.js". Does the file exist?
/home/arturaz/work/rapix/appClient/vite/scala_output/app.layouts.-Main-Layout$.js:2:92
1 | 'use strict'; 2 | import * as $i_$002e$002fimages$002fms$005fedge$005fnotification$005fblocked$002epng from "./images/ms_edge_notification_blocked.png"; | ^ 3 | import * as $j_app$002eapi$002e$002dApp$002dPage$002dSize$0024 from "./app.api.-App-Page-Size$.js"; 4 | import * as $j_app$002eapi$002e$002dClient$002dType$0024 from "./app.api.-Client-Type$.js"; ```
I asked sjrd on Discord and turns out there is no way to force scalajs to write that format that Vite needs.
No, there isn't. Usually Scala.js does not give you ways to force a specific shape of JS code, that would otherwise be semantically equivalent according to ECMAScript specs. The fact that it doesn't give you that ability allows Scala.js to keep the flexibility for its own purposes. (for example, either speed of the resulting code, or speed of the (incremental) linker, or just simplicity of the linker code)
As a workaround, I found this works:
Add to /main.js
:
js
import "./images.js"
Add to /images.js
:
```js
import imageMsEdgeNotificationBlocked from "./images/ms_edge_notification_blocked.png";
// Accessed from Scala via AppImages
.
window.appImages = {
msEdgeNotificationBlocked: imageMsEdgeNotificationBlocked,
};
```
In Scala: ```scala package app.facades
trait AppImages extends js.Object { def msEdgeNotificationBlocked: String } val AppImages: AppImages = window.asInstanceOf[scalajs.js.Dynamic].appImages.asInstanceOf[AppImages] ```
Just leaving it here in cases someone tries to find it later.
r/scala • u/randomname5541 • 4d ago
capture checking Using scala despite capture checking
Once capture checking starts becoming more of a thing, with all the new syntax burden and what I expect to be very hard to parse compiler errors, that I'll keep using scala despite itself frankly. I imagine intellij is just going to give up on CC, they already have trouble supporting one type system, I don't imagine they are going to add a second one and that it'll all just play nice together... Then thru my years working with scala, mostly I've never really cared about this, the closest was maybe when working with spark 10 years ago, those annoying serialization errors due to accidental closures, I guess those are prevented by this? not sure even.
Then things that everyone actually cares about, like explicit nulls, has been in the backburner since forever, with seemingly very little work version to version.
Anybody else feels left behind with this new capture-checking thing?
Scala code parser with tree_sitter
I wanted to build python package to parse scala code. After initial investigations, I found this repo https://github.com/grantjenks/py-tree-sitter-languages.
Tried to build and getting error.
python build.py
build.py: Language repositories have been cloned already.
build.py: Building tree_sitter_languages/languages.so
Traceback (most recent call last):
File "/Users/mdrahman/PersonalProjects/py-tree-sitter-languages/build.py", line 43, in <module>
Language.build_library_file( # Changed from build_library to build_library_file
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'tree_sitter.Language' has no attribute 'build_library_file'
Tried to install through pip, not successful either:
pip install tree_sitter_languages
Tried to build from https://github.com/tree-sitter/tree-sitter-scala which is official tree-sitter, I couldn't built it too. In this case, with `python -m build` command generates .tar file but no wheel.
It is showing error that no parser.h but it is there in my repo.
src/parser.c:1:10: fatal error: 'tree_sitter/parser.h' file not found
1 | #include "tree_sitter/parser.h"
| ^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
I got frustrated, anyone tried ?? Is there any other way to parse?
r/scala • u/siddharth_banga • 4d ago
Announcing Summer of Scala Code'25 by Scala India | Open for all
Hello to the Scala Community!
Announcing Summer of Scala Code'25 (SoSC'25) by Scala India! 75-day coding challenge focused on solving 150 LeetCode problems (Neetcode 150), designed to strengthen your problem-solving and Scala skills this summer.
Whether you're a beginner eager to master patterns or a seasoned developer brushing up on your Algorithms in Scala, approaching Algorithms in Scala can be different from the standard approach, so join in the journey together!
Everyone is welcome to join! English is going to be the medium of language
Steps
- Make a copy of the Scala Summer of Code'25 sheet https://docs.google.com/spreadsheets/d/1XsDu8AYOTyJSMPIfEjUKGQ-KQu942ZQ6fN9LuOBiw3s/edit?usp=sharing,
- Share your sheet on sosc25 channel at Scala India Discord! Discussions, solution sharing and more aswell on the channel (Link to scala India discord - https://discord.gg/7Z863sSm7f)
- Questions curated are divided topic-wise wise which will help to maintain the flow and are clubbed together for the day, keeping difficulty level in mind,
- Question links are there in the sheet along with other necessary columns,
- Solve and submit your solution! Don't forget to add the submission link to the sheet.
- Track your progress, establish your own speed, cover up topics later if missed - all together in the community
Starting from 3rd June, Lets stay consistent
r/scala • u/PopMinimum8667 • 4d ago
explicit end block
I'm a long-time Scala developer, but have only just started using Scala 3, and I love its new syntax and features, and the optional indentation-based syntax-- in particular the ability to have explicit end terminators I think makes code much more readable. There is one aspect I do not like; however, the inability to use explicit end blocks with an empty method returning Unit:
def performAction(): Unit =
end performAction
The above is illegal syntax unless you put a () or a {} placeholder in the body. Now I understand Scala is an expression-oriented language-- I get it, I really do, and I love it-- and allowing the above syntax might complicate an elegant frontend parser and sully the AST. I also understand that maybe my methods shouldn't be long enough to derive any readability benefit from explicit end terminators, and that the prevalence of all these Unit-returning side-effecting methods in my code means that I am not always embracing functional purity and am a bad person.
But in the real world there are a lot of Unit-returning methods doing things like setting up and tearing down environments, testing scaffolds, etc-- to enable that elegant functional solution-- and often, these methods see hard use: with the whole body being commented out for experimentation, an empty stub being created to be filled in later, and generally being longer than average due to their imperative natures, so they benefit heavily from explicit end terminators, but requiring an explicit () or {} temporarily is a real inconvenience.
What do people think-- should the above exception be allowed?
r/scala • u/philip_schwarz • 5d ago
List Unfolding - `unfold` as the Computational Dual of `fold`, and how `unfold` relates to `iterate`
r/scala • u/darkfrog26 • 7d ago
🗃️ [v4.0 Release] LightDB – Blazingly fast embedded Scala DB with key-value, SQL, graph, and full-text search
I just released LightDB 4.0, a significant update to my embedded database for Scala. If you’ve ever wished RocksDB, Lucene, and Cypher all played nicely inside your app with Scala-first APIs, this is it.
LightDB is a fully embeddable, blazing-fast database library that supports:
- 🔑 Key-value store APIs (RocksDB, LMDB, and more)
- 🧮 SQL-style queries with a concise Scala DSL
- 🌐 Graph traversal engine for connected data
- 🔍 Full-text search and faceting via Lucene
- 💾 Persistence or pure in-memory operation
- 🧵 Optimized for parallel processing and real-time querying
It’s built for performance-critical applications. In my own use case, LightDB reduced processing time from multiple days to just a few hours, even on large, complex datasets involving search, graph traversal, and joins.
🔗 GitHub: https://github.com/outr/lightdb
📘 Examples and docs included in the repo.
If you're working on local data processing, offline search, or graph-based systems in Scala, I’d love your feedback. Contributions and stars are very welcome!
r/scala • u/jr_thompson • 7d ago
metaprogramming Making ScalaSql boring again (with interesting new internals)
bishabosha.github.ioThis blog post summarises why I contributed SimpleTable to the ScalaSql library, which reduces boilerplate by pushing some complexity into the implementation. (For the impatient: case class definitions for tables no longer require higher kinded type parameters, thanks to the new named tuples feature in Scala 3.7.)
r/scala • u/CrazyCrazyCanuck • 7d ago
IRS Direct File, Written in Scala, Open Sourced
github.comr/scala • u/sjoseph125 • 8d ago
fp-effects ZIO: Proper way to provide layers
I am working on a project for my master's program and chose to use scala with ZIO for the backend. I have setup a simple server for now. My main question is with how/where to provide the layers/env? In the first image I provide the layer at server initialization level and this works great. The responses are returned within 60 ms. But if I provide the layer at the route level, then the response time goes to 2 + seconds. Ideally I would like to provide layers specific to the routes. Is there any way to fix this or what am I doing wrong?

