/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
I am recreating the architecture of my current employeer (mid-size insurance company) but done correctly (at a very basic level of course) as a personal project. I'm a fan of type safety, the APIs were already built using Smithy, the frontend using ScalaJs and of course, all the microservices in Scala.
My doubt comes when interacting with messaging brokers (Kafka or RabbitMQ) is there any way to generate a “contract” to have type safety in the messages that are sent?
- I know that Smithy is protocol agnostic, but I can't find any examples where it is used for brokers, is this possible?
- I was thinking about a shared library with all the types that will be send/received from the broker. But this probably will introduce a problem with versioning and force me to re deploy multiple microservices just because some type in the shared library changed.
I am looking for a bachelor thesis topic. I want to pick a topic related to programming languages, compilers, maybe some debuggers. These falls in more of a informatics theory field, but my specialization is software engineering. That’s why I need to find something related to software but indeed have connections to my interests.
Could anybody recommend any interesting topics that I might pick?
Target languages of a lab I want to work with are Javascript, R, Julia, Racket and Scala
I have a codebase in java that I need to port over to scala. Whats my best best on porting it over as quickly as possible. Are there any tools that allow you to do that. Does anyone know people who do this kind of stuff professionally.
Here it is - the latest edition of the Scalendar newsletter. This month is packed with plenty of Scala meetups, so don’t miss out! ;) Take a look here: https://scalac.io/blog/scalendar-november-2024/
P.S. If you're looking for new growth opportunities and exciting projects in Scala... Scalac is currently recruiting ;) You can find the latest job openings at the end of the Scalendar and on our website in the careers section.
Clash of IO, background removed using AI
🎉🎉 Adam Hearn is joining us next week, to teach us about Kyo with a Talk + Workshop 🎉🎉
Plenty of thanks to Kyo's contributors, we might be the first Scala conference to have a presentation on Kyo!
https://scala.io/sessions/paris-2024/building-robust-applications-with-kyo-intro
https://scala.io/sessions/paris-2024/building-robust-applications-with-kyo
You can get tickets directly here : https://scala.io
---
Effect systems have been a major subject in the community, for the past 10 years, especially for the past 6 years, we had the chance to have great speakers on the matter to share they thought about it. We keep this playlist updated : https://www.youtube.com/playlist?list=PLjkHSzY9VuL8wHLPlQIx0QnbFSHHqF8gB
It's a pleasure to have Kyo at the conference, reinforcing our mission to create a welcoming space where Scala enthusiasts can share ideas, even when they differ. After featuring Ox in February and more ZIO content in 2022, the clash of IO a couple of years ago, a joint talk on "Performance and Compatibility Hybrids Kyo/Ox/Caprese Apps on the JVM" next year would be fantastic!
I've got some issues with Pekko code and I believe it's related to the fact that the default Flow already materializes the data:
```
def addSha(request: HttpRequest)(using
as: ActorSystem[Any],
ec: ExecutionContext
): Future[HttpResponse] =
request.entity.dataBytes
.via(computeHashWithPayloadAndPayloadLength)
.map { out =>
request
.withEntity(out._2)
.addHeader(new RawHeader("sha", out._1.digest().map("%02x".format(_)).mkString))
}
.via(Http().outgoingConnection)
.runWith(Sink.head)
private def computeHashWithPayloadAndPayloadLength: Flow[ByteString, (MessageDigest, ByteString, Int), NotUsed] =
Flow[ByteString].fold((MessageDigest.getInstance("SHA-256"), ByteString.empty, 0)) { (acc, chunk) =>
acc._1.update(chunk.toByteBuffer)
(acc._1, acc._2 ++ chunk, acc._3 + chunk.length)
}
```
Basically I need the request body in order to compute an hash and add it to the headers, forcing me to consume the source. If I comment this line
```//.withEntity(out._2)```
it returns the error:
> substream source cannot be materialized more than once
because the flow I'm using is the default Pekko Http one (Http().outgoingConnection) and it seems to materialize the data. By using the .withEntity I'm creating another entity stream that can then be consumed another time.
Now onto my question: is there any way to solve this (maybe by using another pekko http flow) without having to re-implement the Http().outgoingConnection with the hash computing part?
Hi everyone, could someone here maybe help me? I can not understand why this code throws a NullPointerException in the println:
import java.util.HashMap;
class Main {
def main() {
val map = new HashMap();
val nullobj = map.get("foo");
println(nullobj == null)
}
}
This seems to somehow be an issue with the type inference: The type gets inferred as `Nothing` and specifying any other type for `nullobj` makes the code work.
Thanks in advance!
Hey there
I'm a software engineer mostly using C#/.NET for backend services and I've been interested in distributed systems for a while. Obviously going down the rabbit hole of dist sys, one comes across functional programming languages, concurrency models, BEAM, Go, Actor model etc. While I do like Go and Elixir, job prospects where I live don't offer that many roles using those technologies. There are however a fair amount of Scala roles where I live, and I know Scala + Akka also used to build scalable and fault-tolerant systems (Twitter/X being a major example).
I would be keen to enter a backend role using Scala but I am just wondering about the Scala ecosystem. The problem I have with the .NET ecosystem, is that it is a rather boring ecosystem outside of Microsoft's technologies. Want an ORM? Use Entity Framework Core. Want a SQL DB? Use Microsoft SQL Server. Want a NoSQL DB? Use Azure Cosmos DB. Yes there are a lot of alternatives, but they are few and far between, enterprises would rather just stick to Microsoft's solutions and the open source ecosystem is very limited. Is this similar with regards to the Scala ecosystem? Would you recommend going into Scala?
Any advice would be appreciated :)
Finally, we are announcing it, due to the organization of an indie conference, it always takes more time to communicate!
Valentin Kasas, that some of you know from the previous edition of the conference in Lyon, is coming back from under his rock to open our conference.
Valentin, true to his name, will talk about our specific subject of interest, Scala, with a dash of Love.
Where to watch it?
Can't wait to open the door of the conference next week!
https://scala.io/sessions/paris-2024/surprise-opening-keynote
I take a look at what typeclasses are, how we can use them in Java, why nobody does and why they are so prevalent in Scala.
This sounds simple, but I can't seem to serve static files from ZIO. I literally copied code from the documentation
import zio._
import zio.http._
object StaticFiles extends ZIOAppDefault {
/**
* Creates an HTTP app that only serves static files from resources via
* "/static". For paths other than the resources directory, see
* [[zio.http.Middleware.serveDirectory]].
*/
val routes = Routes.empty @@ Middleware.serveResources(Path.empty / "static")
override def run = Server.serve(routes).provide(Server.default)
}
And put a file.js in src/main/resources/file.js
But when I access localhost:8080/static/file.js it returns a 404.
I have been working on a PR for Scala Metals recently. I use Emacs, so I ended up adding an utility to quickly refresh the Metals snapshot to test my latest changes.
I wrote about it here, if anybody else uses that editor: https://ag91.github.io/blog/2024/10/27/tips-to-contribute-to-scala-metals-lsp-server-with-emacs/
Also not sure if it would be of interest to write down how adding a Code Action to Metals works for potential future contributors?
Here are results of benchmarks for jsoniter-scala Vs simdjson-java (parsing of different sizes of strings and arrays of booleans and numbers, tested on JDK-24).
TLDR: simdjson-java outperforms only in parsing of long ASCII strings: https://github.com/plokhotnyuk/jsoniter-scala/compare/master...simdjson#diff-f4916c36d9b86fe29ebd1ca34d19acb6b834dc1fecf5149c5cb319ee4bca2919R1
Also, simdjson-java is faster in skipping of JSON input that is not going to be decoded to some fields of resulting product-type instance: https://github.com/simdjson/simdjson-java?tab=readme-ov-file#512-bit-vectors
When using Oracle GraalVM JDK results for jsoniter-scala are better at ~10%, but simdjson-java slows down in 100x times or more because incubating JDK extension for vectors is not supported in GraalVM yet.
enum Permission:
case SuperUser extends Permission
case Admin(organization: String) extends Permission
given superUserEncoder: JsonEncoder[Permission.SuperUser.type] = ???
given adminEncoder: JsonEncoder[Permission.Admin.type] = ???
// No given instance of type zio.json.JsonEncoder[Permission]
val p = Permission.SuperUser.toJson
I want to use a different encoder depending on the enum type. How can I get this to work?
enum TimeSpan:
case All extends TimeSpan
case Until(end: LocalDateTime) extends TimeSpan
case InclusiveStartExlusiveEnd(start: LocalDateTime, end: LocalDateTime)
extends TimeSpan
I want to have something like this to validate the input before creating an instance of InclusiveStartExlusiveEnd
object InclusiveStartExlusiveEnd:
def apply(
start: LocalDateTime,
end: LocalDateTime
): Validated[String, InclusiveStartExlusiveEnd] = ???
Is it possible with the scala 3 enum syntax?
Adrien Piquerez at the Scala Center writes on Mastodon:
Yesterday I deployed the new Scaladex API, which you can use to get the list of all Scala projects and artifacts, filtered by Scala version, or platform: JVM, Scala.js, Scala Native, or sbt and Mill for plugins.
Check it out here: https://index.scala-lang.org/api/doc/
I need to introduce some endpoints on a legacy system and I'm having some problem with the actor system. I also have some ideas about the actor system:
I'm thinking on just using the HTTP server and then just calling regular Scala code. Is this a bad thing?
- Bloop 2
- detecting custom mains
Try it out in your favourite editor!
Read more about the reasons and what next steps are planned.
/**With the following method structure*/
var a = Some(123)
def func1() =
a match
case Some(a) => 123
case other => "123"
def func2(i: Int) = print(i)
def func2(s: String) = print(s)
/**is there a way to write the following in shorter form*/
func1() match
case a: Int => func2(a)
case b: String => func2(b)
/**Like this*/
//func2(func1())
Hi,
I'm the maintainer of Peloton, an actor library for Cats Effect that has recently been accepted as a Typelevel affiliate project.
While being heavily inspired by Akka, the main goal for Peloton was not to be as close to Akka as possible, but to adopt modern Scala 3 and make use of Cats Effect.
To this date, most of the features incorporated into the project originated from personal requirements, but now, especially as an affiliate project, I need some feedback and feature ideas from the community. I created a discussion over at the GitHub project for this. Please join and discuss if you're interested in Peloton. Of course, new contributors are also always welcome.
Thanks!