itkpi / cakeless Goto Github PK
View Code? Open in Web Editor NEWWire your cakes automatically to zio environment
License: Apache License 2.0
Wire your cakes automatically to zio environment
License: Apache License 2.0
Currently CakeT is only derived with cats.Id.
Need to provide implicit derivation for CakeT[IO, ?]
Integrate with scalaz-zio
Having feedback about cakeless I disired to make 2 separate wiring
approaches.
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
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.
2.13 is out now! Also, literal singletons may replace some usages of Witness.`"string"`.T
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.