Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dependency Injection docs #195

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Dependency Injection docs #195

wants to merge 2 commits into from

Conversation

peterneyens
Copy link
Member

@peterneyens peterneyens commented Apr 10, 2017

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-io
Copy link

codecov-io commented Apr 10, 2017

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.

@raulraja
Copy link
Contributor

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

@raulraja raulraja self-requested a review April 11, 2017 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants