Getting Started with λÆS
Installation
The library is available on Maven Central. Add the following 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 data structures
)
The library is only available for Scala 3 and is currently in an experimental stage. The API is subject to change.
Modules
- yaes-core: Essential effects for functional programming (IO, Async, Raise, etc.)
- yaes-data: Functional data structures that work with effects (Flow, etc.)
Your First Effect
Let’s start with a simple example using the Random
and Raise
effects:
import in.rcard.yaes.Random.*
import in.rcard.yaes.Raise.*
def flipCoin(using Random, Raise[String]): String = {
val result = Random.nextBoolean
if (result) "Heads" else "Tails"
}
Running Effects
To execute the effectful computation, use handlers:
import in.rcard.yaes.Random.*
import in.rcard.yaes.Raise.*
val result: String = Raise.run {
Random.run {
flipCoin
}
}
Key Concepts
Effects vs Side Effects
- Side Effect: An unpredictable interaction, usually with an external system
- Effect: A managed side effect wrapped in the λÆS system
Deferred Execution
Calling effectful functions doesn’t immediately execute them. Instead, they return a value representing a computation that can be run later.
Handlers
Handlers are the tools that execute deferred effects. They can be composed and applied selectively.
Next Steps
- Explore the available effects
- Learn about functional data structures
- Check out practical examples
- Read about contributing