Contributors Wanted

Build Status codecov.io Maven Central Latest version License Join the chat at https://gitter.im/47deg/freestyle GitHub Issues Scala.js

A Cohesive & Pragmatic Framework of FP centric Scala libraries

Build purely functional applications and libraries

Build stack-safe purely functional applications and libraries that support parallel and sequential computations where declaration is decoupled from interpretation. Freestyle encourages programs built atop Free algebras that are interpreted at the edge of your application ensuring effects are localized and performed in a controlled environment. Applications built with Freestyle can be interpreted to any runtime semantics supported by the interpreter target type.

import freestyle._

@free trait Database {
  def get(id: UserId): FS[User]
}

@free trait Cache {
  def get(id: UserId): FS[User]
}

@module trait Persistence {
  val database: Database
  val cache: Cache
}

Automatic Dependency Injection

Freestyle includes all the implicit machinery necessary to achieve seamless dependency injection of @free and @module Algebras. Simply require any of your @free or @module trait as implicits where needed.

def storedUsers[F[_]]
    (userId: UserId)
    (implicit persistence: Persistence[F]): FreeS[F, (User, User)] = {
  import persistence._
  for {
    cachedUser <- cache.get(userId)
    persistentUser <- database.get(userId)
  } yield (cachedUser, persistentUser)
}

Ready to use integrations

Freestyle ships with ready to use algebras and convenient syntax extensions covering most of the application concerns such as persistence, configuration, logging, etc. In addition Freestyle includes commonly used FP effects stack such as option, error, reader, writer, state based on the capabilities of the target runtime interpreters.

def loadUser[F[_]]
  (userId: UserId)
  (implicit 
    doobie: DoobieM[F], 
    logging: LoggingM[F]): FreeS[F, User] = {
    import doobie.implicits._
    for {
      user <- (sql"SELECT * FROM User WHERE userId = $userId"
                .query[User]
                .unique
                .liftFS[F])
      - <- logging.debug(s"Loaded User: ${user.userId}")
    } yield user
}

Modules

  • freestyle - Core module including building blocks for boilerplate free FP programs and apps over Free monads and cats.

  • tagless - An alternative encoding to Free based on Tagless Final.

  • effects - MTL style effects such as reader, writer, state, error, and more modeled as free algebras.

  • logging - A purely functional logging algebra over Verizon's Journal.

  • cache - A generic cache with in memory and redis based implementations.

Integrations

Freestyle integrations are located at https://github.com/frees-io/freestyle-integrations.

  • fetch - Integration with the Fetch library for efficient data access from heterogenous datasources.

  • fs2 - Integration to run fs2 Streams in Freestyle programs.

  • monix - Instances and utilities to interpret to monix.eval.Task.

  • slick - Embedding of DBIO actions in Freestyle programs.

  • doobie - Embedding of Doobie ConnectionIO actions in Freestyle programs.

  • http - Adapters and marshallers to run the Freestyle program in endpoint return types for akka-http, finch, http4s and play.

Freestyle Artifacts

Freestyle is compatible with both Scala JVM and Scala.js.

This project supports Scala 2.11 and 2.12. The project is based on scalameta.

To use the project, add the following to your build.sbt:

addCompilerPlugin("org.scalameta" % "paradise" % "3.0.0-M8" cross CrossVersion.full)

For Scala.jvm:

// required
libraryDependencies += "io.frees" %% "freestyle"              % "0.3.1"

// optional - effects and patterns
libraryDependencies += "io.frees" %% "freestyle-effects"      % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-tagless"      % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-async"        % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-async-fs2"    % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-async-monix"  % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-cache"        % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-config"       % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-logging"      % "0.3.1"

// optional - integrations
libraryDependencies += "io.frees" %% "freestyle-cache-redis"  % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-doobie"       % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-fetch"        % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-fs2"          % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-http-akka"    % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-http-finch"   % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-http-http4s"  % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-http-play"    % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-monix"        % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-slick"        % "0.3.1"
libraryDependencies += "io.frees" %% "freestyle-twitter-util" % "0.3.1"

For Scala.js:

// required
libraryDependencies += "io.frees" %%% "freestyle"             % "0.3.1"

// optional - effects and patterns
libraryDependencies += "io.frees" %%% "freestyle-effects"     % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-tagless"     % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-async"       % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-async-fs2"   % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-async-monix" % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-cache"       % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-logging"     % "0.3.1"

// optional - integrations
libraryDependencies += "io.frees" %%% "freestyle-fetch"       % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-fs2"         % "0.3.1"
libraryDependencies += "io.frees" %%% "freestyle-monix"       % "0.3.1"

Freestyle in the wild

If you wish to add your library here please consider a PR to include it in the list below.

scala-exercises scala-exercises Scala Exercises is an Open Source project for learning different technologies based in the Scala Programming Language.

Commercial Support

47 Degrees offers commercial support for the Freestyle framework and associated technologies. To find out more, visit 47 Degrees' Open Source Support.

Copyright

Freestyle is designed and developed by 47 Degrees

Copyright (C) 2017 47 Degrees. http://47deg.com