0

I am currently following Miss Wiem Zine's article (specifically on ZIO): Make your program testable

but I couldn't get pass the

package console {
  def println(line: String): ZIO[Console, Nothing, Unit] =
    ZIO.accessM(_.console println line)

  val readLine: ZIO[Console, Nothing, String] = 
    ZIO.accessM(_.console.readLine)
}

I've read in alvin alexander's page, but it's all about scoping.

I tried it in intellij, but it complains.

Could it be a

package object console {
...
}

instead of package console {}?

Or is that a scala 3 thing? Or am I doing something wrong?

cchantep
  • 9,118
  • 3
  • 30
  • 41
Jitterbug
  • 302
  • 1
  • 11
  • 3
    I think it is a Scala 3 thing: https://stackoverflow.com/a/56566166/14955 – Thilo Sep 20 '19 at 06:30
  • 1
    the other examples use `package object` see for Example: https://github.com/jdegoes/functional-scala/blob/master/src/main/scala/net/degoes/06-application/configuration/package.scala – pme Sep 20 '19 at 07:01
  • @Thilo thanks for the link. I don't usually use it too, just only found out about it when I started studying zio. – Jitterbug Sep 20 '19 at 07:11
  • @pme since you've mention it, I scourged articles from John De Goes and finally found it: http://degoes.net/articles/zio-environment Thanks for the help! – Jitterbug Sep 20 '19 at 07:18

1 Answers1

1

In Scala 2, we have a concept of package objects. There are examples here: https://www.scala-lang.org/docu/files/packageobjects/packageobjects.html.

I think code snippet from "Wiem Zine's article" is missing object keyword, so you are right it should be: package object console, since the whole example is on ZIO and Scala 2.x. There is no ZIO for Scala 3 yet, as far as I know :-)

@Thilo is also right that Scala 3 allows us to use top-level definitions right in the file without necessity to wrap into a block. Until Scala 3, one can use package object to get common package code.

Alexey Novakov
  • 744
  • 6
  • 20