Open steinybot opened 6 years ago
This seems to work:
object collection {
type NonEmptyList[A] = List[A] Refined NonEmpty
object NonEmptyList {
class NonEmptyListOps[A] extends RefinedTypeOps[NonEmptyList[A], List[A]] {
def fromCons(cons: ::[A]): NonEmptyList[A] =
Refined.unsafeApply(cons)
}
def apply[A]: NonEmptyListOps[A] = new NonEmptyListOps[A]
}
}
scala> NonEmptyList[String].fromCons(::("hello", Nil))
res5: NonEmptyList[String] = List(hello)
I'm open to adding this to the types
package.
It would be cool if this worked: