Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • May 06 2019 21:34
    jcranky added as member
  • Apr 24 2019 11:03
    etorreborre removed as member
  • Apr 24 2019 11:03
    jcranky removed as member
  • Apr 24 2019 11:03
    danielkarch removed as member
  • Feb 25 2019 21:28
    karlroberts commented #125
  • Feb 12 2019 08:44
    etorreborre closed #125
  • Feb 12 2019 08:44
    etorreborre commented #125
  • Feb 11 2019 08:13
    etorreborre commented #125
  • Feb 10 2019 21:20
    karlroberts opened #125
  • Jan 21 2019 15:14
    etorreborre commented #124
  • Jan 21 2019 15:14
    etorreborre commented #124
  • Jan 18 2019 10:55
    etorreborre commented #124
  • Jan 18 2019 10:55
    etorreborre commented #124
  • Jan 18 2019 10:55
    etorreborre reopened #124
  • Jan 18 2019 10:55
    etorreborre reopened #124
  • Jan 18 2019 08:35
    alvarogimenez commented #124
  • Jan 18 2019 08:35
    alvarogimenez commented #124
  • Jan 18 2019 08:30
    alvarogimenez commented #124
  • Jan 18 2019 08:30
    alvarogimenez commented #124
  • Jan 17 2019 17:15
    etorreborre commented #124
Paulo "JCranky" Siqueira
@jcranky
Perhaps that is why Eric mentioned that grafter won't work out of the box in this scenario ?
Eric Torreborre
@etorreborre
You can still use the GenericReader to create a default instance in the companion object
Daniel Karch
@danielkarch
My problem is that in the companion object of the trait I need explicitly define the instance to use. But I cannot specify, say, FutureFooService.reader because it has the wrong (non-generic) type.
Eric Torreborre
@etorreborre
I'm thinking that In the companion object we can put implicit val reader: Reader[ApplicationConfig, FooService[Task]] = genericReader and then when we finally instantiate the whole application with F = Task this instance should be found. If we need anything else than F = Task we need to provide other instances
Daniel Karch
@danielkarch
You have some components where even the implementation is generic, because they just call their (generic) dependencies, and some components where you only have a specific implementation.
Matthew de Detrich
@mdedetrich
Is there a way to retrieve a singleton class instance from your graph?
Eric Torreborre
@etorreborre
You can collect all the elements of a given type and check if the list has size 1 if you want to check that a singleton exists
Matthew de Detrich
@mdedetrich
Cheers
@etorreborre How exactly do you retrieve the graph from an existing application?
Actually found it, nvm
Eric Torreborre
@etorreborre
cool, I was about to direct you to the QuickStart section
Philipp Martini
@maphi
Hi guys, is it true that nesting configs is not possible? This always fails as scalac is not able to resolve implicits (using lightbend scala 2.12.5):
import cats.Eval
import cats.data.Reader
import cats.implicits._
import org.zalando.grafter.{Start, StartResult}
import org.zalando.grafter.macros.{reader, readers}
import org.zalando.grafter.syntax.rewriter._

@readers
case class ApplicationConfig(httpConfig: HttpConfig)

@readers
case class HttpConfig(cfg1: HttpSubConfig1, cfg2: HttpSubConfig2)

case class HttpSubConfig1(port: Int)
case class HttpSubConfig2(host: String)

@reader
case class HttpClient(config: HttpSubConfig2) extends Start {
  override def start: Eval[StartResult] = StartResult.eval("HttpClient")(println("Start HttpClient"))
}


@reader
case class SomeService(client: HttpClient) extends Start {
  override def start: Eval[StartResult] = StartResult.eval("SomeService")(println("Start SomeService"))
}

@reader
case class Application(someService: SomeService)


object MyApp extends App {
  val config = ApplicationConfig(HttpConfig(HttpSubConfig1(80), HttpSubConfig2("bla")))

  val app = Application.reader[ApplicationConfig].apply(config).singletons

  val started = app.startAll.value

  if (started.forall(_.success))
    println("application started successfully")
  else
    println(started.mkString("\n"))
}
Error is: could not find implicit value for parameter someServiceReader: cats.data.Reader[...ApplicationConfig,....SomeService]
Bjørn Madsen
@aeons
can you try removing the @readers macro on HttpConfig?
i think it might generate an ambiguous implicit value
Philipp Martini
@maphi
Doesn't help. I think its missing an Reader[ApplicationConfig, HttpSubConfig2]
Bjørn Madsen
@aeons
does ApplicationConfig.cfg2Reader exist?
Philipp Martini
@maphi
scalac says no
Bjørn Madsen
@aeons
just for completeness does ApplicationConfig.cfg1Reader exist?
Philipp Martini
@maphi
Nope. Just for completeness: Using grafter 2.6.0
Bjørn Madsen
@aeons
can you try with 2.5.0
i think I might have broken this :|
Philipp Martini
@maphi
ok. just FYI (with 2.6.0): HttpConfig. cfg1Reader/cfg2Reader exists when using @readers on HttpConfig
Bjørn Madsen
@aeons
yeah, that makes sense
I think I’ve misunderstood something with how it should owkr :)
Philipp Martini
@maphi
same problem with 2.5.0
Bjørn Madsen
@aeons
ok, not my fault then :D
Philipp Martini
@maphi
^^ But it should be possible to nest configs?
Bjørn Madsen
@aeons
i thought so
but I can’t see where it can go down a level in the macros
Philipp Martini
@maphi
y that could be the problem as it got a Reader[ApplicationConfig, HttpConfig] and a Reader[HttpConfig, HttpSubConfig2] in scope and if i create Reader[ApplicationConfig, HttpConfig] manually from the two above it works
Bjørn Madsen
@aeons
in the documentation it does mention to annotate the configuration with @readers
which sounds like there’s only supposed to be one :)
Philipp Martini
@maphi
Y, looks like ^^, thanks 4 help. Macro expansion on ApplicationConfig shows only httpConfigReader, applicationConfigReader, thus scalac has no clue how to resolve it. I'll stick with flat config then.
Bjørn Madsen
@aeons
ok
Eric Torreborre
@etorreborre
@maphi I don’t have time to test this idea right now but I think putting a @reader annotation on top of HttpConfig might work, or something… I’ll come back to you
Philipp Martini
@maphi
I tried putting both(@reader and @readers) on top of HttpConfig but that didn't worked.
Eric Torreborre
@etorreborre
Fair enough, I'll check what I can do if can get enough battery time during my flight 😄
Philipp Martini
@maphi
cool thx, nice flight then
Bjørn Madsen
@aeons
Have you tried both at the same time?
Philipp Martini
@maphi
yes
Eric Torreborre
@etorreborre
@maphi I found a solution for this issue which unfortunately is breaking something else. In the meantime things should work if you annotate HttpConfig with @readers and then import HttpConfig._ where you want to create the application. I’ll try to find a fix that’s working in all cases.
Philipp Martini
@maphi
thx @etorreborre i'll try that
Eric Torreborre
@etorreborre
I’m unfortunately not sure that my solution can be implemented with the current Scala macros, we might have to resort to 2 different annotations, one for the “flat” case, one for the “nested” one
Eric Torreborre
@etorreborre
@maphi can you please try grafter-2.6.1 (and annotate your “nested” configs with @readers)?
Philipp Martini
@maphi
works now :), thanks a lot
Eric Torreborre
@etorreborre
Great it wasn’t obvious to get there :-)
Jakub Kozłowski
@kubukoz
hey, has anyone tried using grafter with Play?
Eric Torreborre
@etorreborre
I haven't but that's something I wanted to investigate