8000 GitHub - malzzz/freestyle: A cohesive & pragmatic framework of FP centric Scala libraries
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

A cohesive & pragmatic framework of FP centric Scala libraries

License

Notifications You must be signed in to change notification settings

malzzz/freestyle

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EXPERIMENTAL, UNRELEASED WIP.

codecov Build Status Join the chat at https://gitter.im/47deg/freestyle

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[F[_]] {
  def get(id: UserId): FreeS[F, User]
}

@free trait Cache[F[_]] {
  def get(id: UserId): FreeS[F, User]
}

@module trait Persistence[F[_]] {
  val database: Database[F]
  val cache: Cache[F]
}

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
}

About

A cohesive & pragmatic framework of FP centric Scala libraries

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Scala 99.7%
  • Shell 0.3%
0