λÆS - Yet Another Effect System

Yet Another Effect System (λÆS)

GitHub Workflow Status Maven Central GitHub release javadoc

λÆS is an experimental effect system in Scala inspired by the ideas behind Algebraic Effects. Using Scala 3 context parameters and context functions, it provides a way to define and handle effects in a modular and composable manner.

Watch the talk from Scalar 2025 about the main concepts behind the library:

Watch the video

📦 Available Modules

λÆS Core

The core module provides a comprehensive set of effects for functional programming:

λÆS Data

The data module provides functional data structures optimized for use with effects:

🚀 Quick Start

Add the dependencies to your build.sbt:

libraryDependencies ++= Seq(
  "in.rcard.yaes" %% "yaes-core" % "0.5.0",
  "in.rcard.yaes" %% "yaes-data" % "0.5.0"  // Optional: for Flow and other data structures
)

✨ What’s New in λÆS?

You can choose between monadic style:

import in.rcard.yaes.Random.*
import in.rcard.yaes.Raise.*
import in.rcard.yaes.Yaes.*

def drunkFlip(using Random, Raise[String]): String = for {
  caught <- Random.nextBoolean
  heads  <- if (caught) Random.nextBoolean else Raise.raise("We dropped the coin")
} yield if (heads) "Heads" else "Tails"

Or a more direct style:

import in.rcard.yaes.Random.*
import in.rcard.yaes.Raise.*

def drunkFlip(using Random, Raise[String]): String = {
  val caught = Random.nextBoolean
  if (caught) {
    val heads = Random.nextBoolean
    if (heads) "Heads" else "Tails"
  } else {
    Raise.raise("We dropped the coin")
  }
}

🎯 Core Concepts

In λÆS, types like Random and Raise are Effects:

λÆS uses deferred execution - calling effectful functions returns a value that represents something that can be run but hasn’t yet.

🛠 Effect Management

Effects are managed using Handlers:

import in.rcard.yaes.Random.*
import in.rcard.yaes.Raise.*

val result: String = Raise.run { 
  Random.run { 
    drunkFlip
  }
}

📚 Available Effects

🗃 Data Structures

🤝 Contributing

Contributions are welcome! Please check our contributing guidelines to get started.

🙏 Acknowledgments

Special thanks to all the smart engineers who helped with ideas and suggestions, including Daniel Ciocîrlan, Simon Vergauwen, Jon Pretty, Noel Welsh, and Flavio Brasil.