Coder Social home page Coder Social logo

paddymahoney / freestyle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from frees-io/freestyle

0.0 2.0 0.0 4.19 MB

A cohesive & pragmatic framework of FP centric Scala libraries

Home Page: http://frees.io/

License: Apache License 2.0

Scala 98.65% Java 1.35%

freestyle's Introduction

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 macro paradise.

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

addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)

For Scala.jvm:

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

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

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

For Scala.js:

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

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

// optional - integrations
libraryDependencies += "io.frees" %%% "freestyle-fetch"       % "0.1.1"
libraryDependencies += "io.frees" %%% "freestyle-fs2"         % "0.1.1"
libraryDependencies += "io.frees" %%% "freestyle-monix"       % "0.1.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.

Copyright

Freestyle is designed and developed by 47 Degrees

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

freestyle's People

Contributors

47degdev avatar 47degfreestyle avatar adrianrafo avatar anamariamv avatar andyscott avatar diesalbla avatar dominv avatar fedefernandez avatar fommil avatar franciscodr avatar gruggiero avatar guersam avatar jdesiloniz avatar jorgegalindocruces avatar jrgonzalezg avatar juanpedromoreno avatar maureenelsberry avatar peterneyens avatar raulraja avatar suhasgaddam avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.