Upgrade to Pro — share decks privately, control downloads, hide ads and more …

9 Cards Architecture

Javi Pacheco
February 18, 2017

9 Cards Architecture

In this talk, I show how we have created a functional architecture on 9 Cards Project with the support of great libraries from the Typelevel ecosystem such as Cats and Monix

Javi Pacheco

February 18, 2017
Tweet

More Decks by Javi Pacheco

Other Decks in Programming

Transcript

  1. 47deg.com 4 A monad is a triple (T, n, u)

    where T is an endofuntor T: X ->X and n: I -> T and u: T x T -> T are 2 natural transformations satisfying these laws: Identity law: Associative law: u(n(T)) = T = u(T(n)) u(u(T x T) x T) = u(T x u (T x T))
  2. 47deg.com 5 A monad in X is just a monoid

    in the category of endofunctors of X, with product x replaced by composition of endofunctor and unit set by the identity endofunctor In other words:
  3. 47deg.com Option[T] 13 val option1 = Some(1) val option2 =

    Some(3) option1.flatMap (o1 => option2.map(o2 => o1 + o2)) // Some(4) Option Monad
  4. 47deg.com For Comprehension 14 for { o1 <- option1 o2

    <- option2 } yield o1 + o2 // Some(4) Option Monad
  5. 47deg.com Future[T] 15 val future1 = Future(4) val future2 =

    Future(2) for { f1 <- future1 f2 <- future2 } yield f1 - f2 // Future(2) Future Monad
  6. 47deg.com 9 Cards Architecture 18 def loadUsersFromServer(): TaskService[Unit] = for

    { _ <- ui.showLoading() users <- process.getUsers() _ <- ui.loadUsers(users) } yield () TaskService Monad
  7. 47deg.com 9 Cards Architecture 19 def initServices(): TaskService[(Seq[Collection], Seq[App], Moment)]

    = (process.getCollections |@| process.getDockApps|@| process.getCurrentMoment).tupled TaskService Applicative
  8. 47deg.com Run Async 20 loadUsersFromServer().value.runAsync { case Failure(ex) => //

    unhandled exception case Success(Right(value)) => // value case Success(Left(ex)) => // handled exception } Run TaskService