Extensible, effectful DSLs

Create extensible, effectful domain specific languages while separating the effect definition from the effect implementation. Effekt is an implementation of algebraic effects with handlers and allows you to structure your effectful programs in a purely functional way. It thus represents an alternative to monad transformer based program structuring techniques or free monads.

An example

The Twitter-API example shows how to define an effect signature with one effectful operation userTweets. The effect itself can be implemented in many ways by simply implementing the abstract methods in the Twitter trait. It could actually contact the Twitter API (potentially using other effects, like HTTP in the implementation) or it could just return dummy tweets for testing purposes. We chose the latter for the implementation of twitterStub and thus running the result actually perform the side-effects always gives the same results.

You can find the full sources for this example in this Dotty Scastie.

Effect signature

trait Twitter {
  def userTweets(userId: Long): Control[List[Tweet]]
}

Effect usage

def query(T: Twitter): Control[List[Tweet]] =
  for {
    ts1 <- T.userTweets(133452)
    ts2 <- T.userTweets(111345)
  } yield ts1 ++ ts2

val result = twitterStub { query }

Getting Started

To use Effekt (tested with Scala 2.11 and Scala 2.12), include the following line to your build.sbt file:

resolvers += Opts.resolver.sonatypeSnapshots

libraryDependencies += "de.b-studios" %% "effekt" % "0.4-SNAPSHOT"

To learn how to use the library, see Your First Effect.