zio / zio-prelude

A lightweight, distinctly Scala take on functional abstractions, with tight ZIO integration

Home Page:https://zio.dev/zio-prelude

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to use extensions for NewtypeF

ajaychandran opened this issue · comments

The following example fails to compile.

import zio.prelude._

type PropF[+A] = PropF.Type[A]
object PropF extends NewtypeF {

  implicit class PropInt(private val self: Type[Int]) extends AnyVal {

    def next: Type[Int] =
      wrap(unwrap(self) + 1)
  }

  implicit class PropNumeric[+A](private val self: Type[A]) extends AnyVal {

    def increment(implicit N: Numeric[A]): Type[A] =
      wrap(N.plus(unwrap(self), N.one))
  }
}


val pf1: PropF[Int] = PropF(1)
val pf2: PropF[Int] = pf1.next  // compile error: value next is not a member of Playground.PropF[Int]
val pf3: PropF[Int] = pf1.increment  // compile error: value increment is not a member of Playground.PropF[Int]

Is this usage incorrect/unsupported?

@ajaychandran You just need to do import PropF._.

Thanks @adamgfraser.

Adding an import statement does resolve the issue but it impacts usability adversely.
I am trying to define new operators so that no extra imports are required (this works for Newtype instances). Is it not possible to do the same with NewtypeF?