/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

53,700 Subscribers

12

Type safety at event broker level. Any suggestion?

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.

5 Comments
2024/11/01
19:33 UTC

3

Bachelor thesis topic

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

6 Comments
2024/11/01
10:11 UTC

20

Move project from Java to 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.

41 Comments
2024/10/31
20:46 UTC

23

Scala conferences in November 2024 | Scalendar

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.

0 Comments
2024/10/30
21:45 UTC

37

ScalaIO: Kyo's talk and workshop!

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!

1 Comment
2024/10/29
19:09 UTC

4

How can I prevent the entity from being materialized more than once in Pekko/Akka?

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?

0 Comments
2024/10/29
10:08 UTC

7

Why does this code throw a NPE?

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!

12 Comments
2024/10/29
08:45 UTC

17

Scala job prospects

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 :)

10 Comments
2024/10/29
06:18 UTC

47

ScalaIO: Surprise Opening Keynote!

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?

  • All the talks are free on YouTube 1 or 2 months after the conference on this channel: https://www.youtube.com/@scalaio (you can subscribe).
  • You can support us directly by buying streaming access to the conference on our website for €85 (2 days of conference, 2 tracks) : scala.io

Can't wait to open the door of the conference next week!

https://scala.io/sessions/paris-2024/surprise-opening-keynote

2 Comments
2024/10/28
21:30 UTC

35

[Presentation] Typeclasses demystified

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.

https://www.youtube.com/watch?v=VDSWjHgM5HA

2 Comments
2024/10/28
15:05 UTC

1

Job Opportunity: Neo4j & Scala

0 Comments
2024/10/28
13:50 UTC

10

Does anybody have an example of a working ZIO HTTP serving static files?

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.

6 Comments
2024/10/28
13:06 UTC

47

Better Java Builds with the Mill Build Tool

0 Comments
2024/10/28
01:27 UTC

19

An Emacs helpful function for contributing to Scala Metals

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?

6 Comments
2024/10/27
22:34 UTC

38

Benchmark results: jsoniter-scala Vs simdjson-java

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.

0 Comments
2024/10/27
15:39 UTC

4

How to provide different json encoder depending on the enum type?

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?

6 Comments
2024/10/27
11:25 UTC

10

Can you create your own companion object for scala 3 enum syntax?

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?

2 Comments
2024/10/27
03:44 UTC

37

Scaladex API (new from the Scala Center)

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/

2 Comments
2024/10/26
00:48 UTC

15

Neo4j / Scala Job Opportunity - reposting from Neo4j’s Sub

0 Comments
2024/10/25
15:47 UTC

17

Is it ok to use Akka HTTP just for the HTTP server and not the actor system?

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:

  1. I don't see value.
  2. I think it's extra complexity for very little gains, I'm running on a single server, I don't need to invoke actors from other servers, so what's the point of actors?
  3. It makes the code more complex.

I'm thinking on just using the HTTP server and then just calling regular Scala code. Is this a bad thing?

20 Comments
2024/10/24
22:28 UTC

98

Metals 1.4.0 is out! 🦆

- Bloop 2

- detecting custom mains

Try it out in your favourite editor!

https://scalameta.org/metals/blog/2024/10/24/palladium

3 Comments
2024/10/24
13:19 UTC

51

Scala 3.6.0 Postmortem has just been published

Read more about the reasons and what next steps are planned.

https://scala-lang.org/news/post-mortem-3.6.0.html

3 Comments
2024/10/24
10:40 UTC

1

Is it possible to directly insert value from method that returns two different types of values into an overloaded method that handles both types?

/**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())
6 Comments
2024/10/23
18:03 UTC

35

Feedback needed: Peloton, an actor library for CE

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!

8 Comments
2024/10/23
13:10 UTC

Back To Top