Thanks Mark. Yes, Scala 3 makes it very convenient to introduce type classes. The example boils down to this in Scala 3:

case class Tweet(

username: String,

content: String,

reply: Boolean,

retweet: Boolean)

given Summary[Tweet]

with extension(tweet: Tweet) def summarize: String =

import tweet._

s"$username: $content"

Then we can call .summarize directly on a Tweet instance. I'll also update the article with this information.

Fehmi Can Saglam
Fehmi Can Saglam

Written by Fehmi Can Saglam

I’m a software engineer based in Berlin. I write mostly about programming and living healthy.

No responses yet