0

I'm trying to do something like this

case class Foo(p: Param)

object Bar {
  def apply(implicit p: Param) = Foo(p)
}

def qux(implicit p: Param) {
  .. something
  val foo: Foo = Bar
  .. use foo
}

what I've reached so far is

object Bar {
  def apply()(implicit p: Param) = Foo(p)
}

def ... {
  val foo: Foo = Bar()
}

Can I do this without parenthesis?

Chaitanya
  • 3,590
  • 14
  • 33
Haedaal
  • 19
  • 1
  • 5

1 Answers1

1

Here's a solution without parenthesis...

case class Foo(p: Param)

object Bar {
  def apply(implicit p: Param) = Foo(p)
}

def qux(implicit p: Param) {
  // .. something
  val foo: Foo = Bar.apply // the only change is here!
  // .. use foo
}

... but with an explicit apply call, which have the advantage to not change your original signature.

Hope it helps.