Code Monkey home page Code Monkey logo

cakeless's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cakeless's Issues

Automatic / semiautomatic wiring

Having feedback about cakeless I disired to make 2 separate wiring approaches.

Semiautomatic wiring

Probably already implemented. Should look like:

import cakeless._
import cats.effect.{IO, IOApp, ExitCode}

trait FooComponent {
  def foo: Int
  def bar: String
}

trait BarComponent {
  def bar: String
  def baz: BigInt
}

object Foo extends CakeWiring[IO] {
  type Component = FooComponent
  case class Dependencies(foo: Int, bar: String)

  def wire = cakeT[IO, Component].as[Dependencies]
}

object Bar extends CakeWiring[IO] {
  type Component = BarComponent
  case class Dependencies(bar: String, baz: BigInt)

  def wire = cakeT[IO, Component].as[Dependencies]
}

object Main extends IOApp {
  def putStrLn(s: Any): IO[Unit] = IO { println(s) }

  case class AllDependencies(foo: Int, bar: String, baz: BigInt)

  def run(args: List[String]): IO[ExitCode] = {
     val program = for {
        foo <- Foo.wire
        bar <- Bar.wire
     } yield foo.foo + foo.bar + bar.baz
    
    program
      .as[AllDependencies]
      .bake(AllDependencies(
         foo = 1,
         bar = "bar",
         baz = BigInt(20000000000)
      ))
      .flatTap(putStrLn)
      .redeem(_ => ExitCode.Error, _ => ExitCode.Success)
  }
}

In this case semiauto means that you explicitly cast dependency type via as method into case class.
Already implemented

Automatic wiring

This should more look like macwire wiring:

import cakeless._
import cats.effect.IO

trait FooComponent {
  def foo: Int
  def bar: String
}

trait BarComponent {
  def bar: String
  def baz: BigInt
}

object Main extends IOApp {
  def putStrLn(s: Any): IO[Unit] = IO { println(s) }

  def run(args: List[String]): IO[ExitCode] = {
     val program = for {
        foo <- cakeT[IO, FooComponent]
        bar <- cakeT[IO, FooComponent]
     } yield foo.foo + foo.bar + bar.baz

    val foo: Int = 1
    val bar: String = "bar"
    val baz: BigInt = BigInt(20000000000)
    
    program.auto // special method using macro-materilized type class
      .flatTap(putStrLn)
      .redeem(_ => ExitCode.Error, _ => ExitCode.Success)
  }
}

Need to implement second version.

Release for 2.13

2.13 is out now! Also, literal singletons may replace some usages of Witness.`"string"`.T

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.