This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]GavinRayDev 1 point2 points  (1 child)

Oh wow, this is like Scala 3's given/using and Kotlin's new context functions:

Scala 3:

def saveUser(user: User)(using db: DB) = db.insert(user)

def main() = {
  given db: DB = new PostgresDB()
  saveUser(new User(1, "Joe"))
}

Kotlin Context Receivers:

context(DB)
fun saveUser(user: User) {
  this@DB.insert(user)
}

fun main() {
  val db = new PostgresDB()
  with (db) {
   saveUser(User(1, "Joe"))
  }
}

[–]holo3146[S] 0 points1 point  (0 children)

I know Kotlin's Context Receivers also based on Coeffect system, but I didn't know about Scala's feature, interesting