freestyle
freestyle copied to clipboard
Dependency Injection docs
Did I miss something, or do we need something else?
I tried to come up with a simple but not too trivial example of using Reader
/ Kleisli
as target data type where you do not want the environment or config to be part of your algebra (like with ReaderM
), but I couldn't come up with something small but still useful.
I don't know if it makes sense to add something trivial like :
@free trait Calc[F[_]] {
def sum(a: Int, b: Int): FreeS[F, Int]
}
type IntReader[A] = Reader[Int, A]
implicit val handler: Calc.Handler[IntReader] = new Calc.Handler[IntReader] {
def sum(a: Int, b: Int): IntReader[Int] = Reader(n => a + (b * n))
}
Calc[Calc.Op].sum(1, 2).exec[IntReader].run(5) // 11 (= 1 + 2 x 5)
Resolves #132.
Codecov Report
Merging #195 into master will not change coverage. The diff coverage is
n/a
.
@@ Coverage Diff @@
## master #195 +/- ##
=======================================
Coverage 71.51% 71.51%
=======================================
Files 38 38
Lines 323 323
Branches 2 2
=======================================
Hits 231 231
Misses 92 92
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update a565432...5b6cd36. Read the comment docs.
I think we need to mention here that we include synthetic implicits in all Algebras and Modules so you can inject them anywhere by requiring them implicitly, that should be the main part of the docs. then provide examples of that. The actual Reader example should be mentioned as an alternative secondary technique just to show that freestyle supports other styles of DI via the reader
effect where you can inject other things beside config